diff --git a/src/JsonSchema/RefResolver.php b/src/JsonSchema/RefResolver.php index 232c4ade..ea0fafd6 100644 --- a/src/JsonSchema/RefResolver.php +++ b/src/JsonSchema/RefResolver.php @@ -102,6 +102,7 @@ public function getUriRetriever() public function resolve($schema, $sourceUri = null) { if (self::$depth > self::$maxDepth) { + self::$depth = 0; throw new JsonDecodingException(JSON_ERROR_DEPTH); } ++self::$depth; diff --git a/tests/JsonSchema/Tests/RefResolverTest.php b/tests/JsonSchema/Tests/RefResolverTest.php index 45ba7150..d9e341db 100644 --- a/tests/JsonSchema/Tests/RefResolverTest.php +++ b/tests/JsonSchema/Tests/RefResolverTest.php @@ -9,6 +9,8 @@ namespace JsonSchema\Tests; +use JsonSchema\Exception\JsonDecodingException; + /** * @group RefResolver */ @@ -355,4 +357,27 @@ public function testMaxDepthExceeded() $resolver->resolve($jsonSchema); } + + public function testDepthRestoration() + { + // stub schema + $jsonSchema = new \stdClass; + $jsonSchema->id = 'stub'; + $jsonSchema->additionalItems = new \stdClass(); + $jsonSchema->additionalItems->additionalItems = 'stub'; + + // stub resolver + \JsonSchema\RefResolver::$maxDepth = 1; + $resolver = new \JsonSchema\RefResolver(); + + try { + $resolver->resolve($jsonSchema); + } catch (JsonDecodingException $e) { + + } + + $reflection = new \ReflectionProperty('\JsonSchema\RefResolver', 'depth'); + $reflection->setAccessible(true); + $this->assertEquals(0, $reflection->getValue()); + } }