diff options
-rw-r--r-- | jsonschema/tests/test_validators.py | 9 | ||||
-rw-r--r-- | jsonschema/validators.py | 7 |
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) |