File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 99
1010namespace JsonSchema ;
1111
12+ use JsonSchema \Exception \JsonDecodingException ;
1213use JsonSchema \Uri \Retrievers \UriRetrieverInterface ;
1314use JsonSchema \Uri \UriRetriever ;
1415
@@ -96,7 +97,7 @@ public function getUriRetriever()
9697 public function resolve ($ schema , $ sourceUri = null )
9798 {
9899 if (self ::$ depth > self ::$ maxDepth ) {
99- return ;
100+ throw new JsonDecodingException ( JSON_ERROR_DEPTH ) ;
100101 }
101102 ++self ::$ depth ;
102103
Original file line number Diff line number Diff line change @@ -334,4 +334,25 @@ public function testFetchRef()
334334
335335 $ this ->assertEquals ($ jsonSchema , $ resolver ->fetchRef ($ ref , $ sourceUri ));
336336 }
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+ }
337358}
You can’t perform that action at this time.
0 commit comments