Skip to content

Commit b2e6b9a

Browse files
committed
Merge pull request #209 from Markard/master
RefResolver::$depth restoration after JsonDecodingException
2 parents 78eab47 + f1e5153 commit b2e6b9a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/JsonSchema/RefResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public function getUriRetriever()
102102
public function resolve($schema, $sourceUri = null)
103103
{
104104
if (self::$depth > self::$maxDepth) {
105+
self::$depth = 0;
105106
throw new JsonDecodingException(JSON_ERROR_DEPTH);
106107
}
107108
++self::$depth;

tests/JsonSchema/Tests/RefResolverTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace JsonSchema\Tests;
1111

12+
use JsonSchema\Exception\JsonDecodingException;
13+
1214
/**
1315
* @group RefResolver
1416
*/
@@ -355,4 +357,27 @@ public function testMaxDepthExceeded()
355357

356358
$resolver->resolve($jsonSchema);
357359
}
360+
361+
public function testDepthRestoration()
362+
{
363+
// stub schema
364+
$jsonSchema = new \stdClass;
365+
$jsonSchema->id = 'stub';
366+
$jsonSchema->additionalItems = new \stdClass();
367+
$jsonSchema->additionalItems->additionalItems = 'stub';
368+
369+
// stub resolver
370+
\JsonSchema\RefResolver::$maxDepth = 1;
371+
$resolver = new \JsonSchema\RefResolver();
372+
373+
try {
374+
$resolver->resolve($jsonSchema);
375+
} catch (JsonDecodingException $e) {
376+
377+
}
378+
379+
$reflection = new \ReflectionProperty('\JsonSchema\RefResolver', 'depth');
380+
$reflection->setAccessible(true);
381+
$this->assertEquals(0, $reflection->getValue());
382+
}
358383
}

0 commit comments

Comments
 (0)