Skip to content

Commit

Permalink
Merge pull request PixarAnimationStudios#2997 from nvmkuruc/arrequire…
Browse files Browse the repository at this point in the history
…strictvalidation

Require strict URI scheme validation for `ArResolver`

(Internal change: 2332296)
  • Loading branch information
pixar-oss committed Jun 28, 2024
2 parents 2cdc3de + f75d65a commit 0b7c06d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 46 deletions.
43 changes: 12 additions & 31 deletions pxr/usd/ar/resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ TF_DEFINE_ENV_SETTING(
PXR_AR_DISABLE_PLUGIN_URI_RESOLVERS, false,
"Disables plugin URI/IRI resolver implementations.");

TF_DEFINE_ENV_SETTING(
PXR_AR_DISABLE_STRICT_SCHEME_VALIDATION, false,
"Disables strict validation for URI/IRI schemes. In future releases, "
"strict validation will be enforced."
);

static TfStaticData<std::string> _preferredResolver;

void
Expand Down Expand Up @@ -1161,32 +1155,19 @@ class _DispatchingResolver final
uriScheme.c_str(),
(*existingResolver)->GetType().GetTypeName().c_str());
}
else if (const auto validation =
_ValidateResourceIdentifierScheme(uriScheme);
!validation.first) {
TF_WARN(
"ArGetResolver(): '%s' for '%s' is not a valid "
"resource identifier scheme: %s. Paths with this "
"prefix will be handled by other resolvers.",
uriScheme.c_str(),
resolverInfo.type.GetTypeName().c_str(),
validation.second.c_str());
}
else {
const auto validation =
_ValidateResourceIdentifierScheme(uriScheme);
if (validation.first) {
uriSchemes.push_back(uriScheme);
}
else if (TfGetEnvSetting(
PXR_AR_DISABLE_STRICT_SCHEME_VALIDATION)){
uriSchemes.push_back(uriScheme);
TF_WARN("'%s' for '%s' is not a valid "
"resource identifier scheme and "
"will be restricted in future releases: %s",
uriScheme.c_str(),
resolverInfo.type.GetTypeName().c_str(),
validation.second.c_str());
} else{
TF_WARN(
"'%s' for '%s' is not a valid resource identifier "
"scheme: %s. Paths with this prefix will be "
"handled by other resolvers. Set "
"PXR_AR_DISABLE_STRICT_SCHEME_VALIDATION to "
"disable strict scheme validation.",
uriScheme.c_str(),
resolverInfo.type.GetTypeName().c_str(),
validation.second.c_str());
}
uriSchemes.push_back(uriScheme);
}
}

Expand Down
19 changes: 4 additions & 15 deletions pxr/usd/ar/testenv/testArURIResolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,10 @@ def test_InvalidScheme(self):
invalid_utf8_path = "test-π-utf8:/abc.xyz"
invalid_numeric_prefix_path = "113-test:/abc.xyz"
invalid_colon_path = "other:test:/abc.xyz"
if Tf.GetEnvSetting("PXR_AR_DISABLE_STRICT_SCHEME_VALIDATION"):
self.assertEqual(resolver.Resolve(invalid_underbar_path),
invalid_underbar_path)
self.assertEqual(resolver.Resolve(invalid_utf8_path),
invalid_utf8_path)
self.assertEqual(resolver.Resolve(invalid_numeric_prefix_path),
invalid_numeric_prefix_path)
# Even when strict scheme validation mode is disabled
# schemes with colons in them may fail to resolve
self.assertFalse(resolver.Resolve(invalid_colon_path))
else:
self.assertFalse(resolver.Resolve(invalid_underbar_path))
self.assertFalse(resolver.Resolve(invalid_utf8_path))
self.assertFalse(resolver.Resolve(invalid_numeric_prefix_path))
self.assertFalse(resolver.Resolve(invalid_colon_path))
self.assertFalse(resolver.Resolve(invalid_underbar_path))
self.assertFalse(resolver.Resolve(invalid_utf8_path))
self.assertFalse(resolver.Resolve(invalid_numeric_prefix_path))
self.assertFalse(resolver.Resolve(invalid_colon_path))

def testGetRegisteredURISchemes(self):
"Tests that all URI schemes for discovered plugins are returned"
Expand Down

0 comments on commit 0b7c06d

Please sign in to comment.