From 150cbaee08f519d1aeec4eb7e75069e1c1c2d808 Mon Sep 17 00:00:00 2001 From: Leif Meyer Date: Thu, 12 Jun 2014 15:19:49 -0600 Subject: [PATCH] Fix UriRetriever::combineRelativePathWithBasePath() does not qualify UriResolverException Added full qualification to UriResolverException in UriRetriever::combineRelativePathWithBasePath(). Added a test to verify that a UriResolverException is thrown when a relative path contains more level-ups than the base path segments. --- src/JsonSchema/Uri/UriRetriever.php | 2 +- tests/JsonSchema/Tests/Uri/UriRetrieverTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/JsonSchema/Uri/UriRetriever.php b/src/JsonSchema/Uri/UriRetriever.php index df3afb1e..4fe696ae 100644 --- a/src/JsonSchema/Uri/UriRetriever.php +++ b/src/JsonSchema/Uri/UriRetriever.php @@ -276,7 +276,7 @@ private static function combineRelativePathWithBasePath($relativePath, $basePath preg_match('|^/?(\.\./(?:\./)*)*|', $relativePath, $match); $numLevelUp = strlen($match[0]) /3 + 1; if ($numLevelUp >= count($basePathSegments)) { - throw new UriResolverException(sprintf("Unable to resolve URI '%s' from base '%s'", $relativePath, $basePath)); + throw new \JsonSchema\Exception\UriResolverException(sprintf("Unable to resolve URI '%s' from base '%s'", $relativePath, $basePath)); } $basePathSegments = array_slice($basePathSegments, 0, -$numLevelUp); diff --git a/tests/JsonSchema/Tests/Uri/UriRetrieverTest.php b/tests/JsonSchema/Tests/Uri/UriRetrieverTest.php index 823e25a2..7409fd23 100644 --- a/tests/JsonSchema/Tests/Uri/UriRetrieverTest.php +++ b/tests/JsonSchema/Tests/Uri/UriRetrieverTest.php @@ -222,4 +222,15 @@ public function testResolvePointerFragmentNoArray() $schema, 'http://example.org/schema.json#/definitions/foo' ); } + + /** + * @expectedException JsonSchema\Exception\UriResolverException + */ + public function testResolveExcessLevelUp() + { + $retriever = new \JsonSchema\Uri\UriRetriever(); + $retriever->resolve( + '../schema.json#', 'http://example.org/schema.json#' + ); + } }