File tree 2 files changed +23
-1
lines changed 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 9
9
10
10
namespace JsonSchema ;
11
11
12
+ use JsonSchema \Exception \JsonDecodingException ;
12
13
use JsonSchema \Uri \Retrievers \UriRetrieverInterface ;
13
14
use JsonSchema \Uri \UriRetriever ;
14
15
@@ -96,7 +97,7 @@ public function getUriRetriever()
96
97
public function resolve ($ schema , $ sourceUri = null )
97
98
{
98
99
if (self ::$ depth > self ::$ maxDepth ) {
99
- return ;
100
+ throw new JsonDecodingException ( JSON_ERROR_DEPTH ) ;
100
101
}
101
102
++self ::$ depth ;
102
103
Original file line number Diff line number Diff line change @@ -334,4 +334,25 @@ public function testFetchRef()
334
334
335
335
$ this ->assertEquals ($ jsonSchema , $ resolver ->fetchRef ($ ref , $ sourceUri ));
336
336
}
337
+
338
+ /**
339
+ * @expectedException \JsonSchema\Exception\JsonDecodingException
340
+ */
341
+ public function testMaxDepthExceeded ()
342
+ {
343
+ // stub schema
344
+ $ jsonSchema = new \stdClass ;
345
+ $ jsonSchema ->id = 'stub ' ;
346
+ $ jsonSchema ->additionalItems = 'stub ' ;
347
+
348
+ // mock retriever
349
+ $ retriever = $ this ->getMock ('JsonSchema\Uri\UriRetriever ' , array ('retrieve ' ));
350
+ $ retriever ->expects ($ this ->any ())->method ('retrieve ' )->will ($ this ->returnValue ($ jsonSchema ));
351
+
352
+ // stub resolver
353
+ \JsonSchema \RefResolver::$ maxDepth = 0 ;
354
+ $ resolver = new \JsonSchema \RefResolver ($ retriever );
355
+
356
+ $ resolver ->resolve ($ jsonSchema );
357
+ }
337
358
}
You can’t perform that action at this time.
0 commit comments