summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Berman <Julian@GrayVines.com>2023-04-25 11:49:30 -0400
committerJulian Berman <Julian@GrayVines.com>2023-04-25 11:49:30 -0400
commit29ad460fb37072200ce019ae4dce4d899350527f (patch)
treeb4238cdc9dcec97c5f821f516e7f97eee0b899d7
parent3b35731082e75d686024342e2507ea50f2ef7657 (diff)
downloadjsonschema-29ad460fb37072200ce019ae4dce4d899350527f.tar.gz
Ignore non-str $ids for *deprecated* RefResolver resolution.v4.18.0a5
The new referencing behavior is more correct (which is why it exists), but also means that even though `RefResolver` was/is untouched, it can be called now with more subschemas than previously, and in some cases that tickles this code to blow up (see the closed issue for a specific example). We simply now ignore non-strs, as doing so is no more wrong than this code used to be. Closes: #1085
-rw-r--r--jsonschema/tests/test_validators.py9
-rw-r--r--jsonschema/validators.py7
2 files changed, 13 insertions, 3 deletions
diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py
index a9b7f6a..00e0c40 100644
--- a/jsonschema/tests/test_validators.py
+++ b/jsonschema/tests/test_validators.py
@@ -2328,6 +2328,15 @@ class TestRefResolver(TestCase):
resolver.pop_scope()
self.assertIn("Failed to pop the scope", str(exc.exception))
+ def test_pointer_within_schema_with_different_id(self):
+ """
+ See #1085.
+ """
+ schema = validators.Draft7Validator.META_SCHEMA
+ resolver = validators._RefResolver("", schema)
+ validator = validators.Draft7Validator(schema, resolver=resolver)
+ self.assertFalse(validator.is_valid({"maxLength": "foo"}))
+
def sorted_errors(errors):
def key(error):
diff --git a/jsonschema/validators.py b/jsonschema/validators.py
index 72af8fc..78e5829 100644
--- a/jsonschema/validators.py
+++ b/jsonschema/validators.py
@@ -1021,9 +1021,10 @@ class _RefResolver:
return None
uri, fragment = urldefrag(url)
for subschema in subschemas:
- target_uri = self._urljoin_cache(
- self.resolution_scope, subschema["$id"],
- )
+ id = subschema["$id"]
+ if not isinstance(id, str):
+ continue
+ target_uri = self._urljoin_cache(self.resolution_scope, id)
if target_uri.rstrip("/") == uri.rstrip("/"):
if fragment:
subschema = self.resolve_fragment(subschema, fragment)