Skip to content

Commit

Permalink
Gut the meat of the recursiveRef implementation for draft2019
Browse files Browse the repository at this point in the history
It's buggy, and can lead to blowing up the stack with recursion errors.

Done by (redundantly) checking schemas during test runs, even though the
upstream test suite 'guarantees' they're valid. (Given that it uses this
implementation to make that guarantee, bugs like the above went unnoticed.)

Closes: #847
  • Loading branch information
Julian committed Jun 28, 2022
1 parent 5fea559 commit 19595b5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion jsonschema/_legacy_validators.py
Expand Up @@ -221,4 +221,8 @@ def recursiveRef(validator, recursiveRef, instance, schema):

fragment = recursiveRef.lstrip("#")
subschema = validator.resolver.resolve_fragment(target, fragment)
yield from validator.descend(instance, subschema)
# FIXME: This is gutted (and not calling .descend) because it can trigger
# recursion errors, so there's a bug here. Re-enable the tests to
# see it.
subschema
return []
1 change: 1 addition & 0 deletions jsonschema/tests/_suite.py
Expand Up @@ -197,6 +197,7 @@ def fn(this):
return unittest.skipIf(reason is not None, reason)(fn)

def validate(self, Validator, **kwargs):
Validator.check_schema(self.schema)
resolver = jsonschema.RefResolver.from_schema(
schema=self.schema,
store=self._remotes,
Expand Down
12 changes: 12 additions & 0 deletions jsonschema/tests/test_jsonschema_test_suite.py
Expand Up @@ -360,6 +360,18 @@ def leap_second(test):
message="dynamicRef support isn't working yet.",
subject="recursiveRef",
)(test)
or skip(
message="These tests depends on dynamicRef working.",
subject="id",
case_description=(
"Invalid use of fragments in location-independent $id"
),
)(test)
or skip(
message="These tests depends on dynamicRef working.",
subject="defs",
description="invalid definition schema",
)(test)
or skip(
message="These tests depends on dynamicRef working.",
subject="anchor",
Expand Down
2 changes: 1 addition & 1 deletion jsonschema/tests/test_validators.py
Expand Up @@ -1410,7 +1410,7 @@ class MetaSchemaTestsMixin(object):
# TODO: These all belong upstream
def test_invalid_properties(self):
with self.assertRaises(exceptions.SchemaError):
self.Validator.check_schema({"properties": {"test": object()}})
self.Validator.check_schema({"properties": 12})

def test_minItems_invalid_string(self):
with self.assertRaises(exceptions.SchemaError):
Expand Down

0 comments on commit 19595b5

Please sign in to comment.