Skip to content

Commit 975f1b0

Browse files
committed
fix UriRetriever not propperly handling missing domain name
1 parent 79e4f40 commit 975f1b0

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/JsonSchema/Uri/UriRetriever.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class UriRetriever
2424
{
2525
protected $uriRetriever = null;
26+
protected $currentSchema = null;
2627

2728
/**
2829
* Guarantee the correct media type was encountered
@@ -112,7 +113,8 @@ public function resolvePointer($jsonSchema, $uri)
112113
public function retrieve($uri, $baseUri = null)
113114
{
114115
$resolver = new UriResolver();
115-
$resolvedUri = $resolver->resolve($uri, $baseUri);
116+
117+
$resolvedUri = $resolver->resolveWithoutFragment($uri, $baseUri);
116118
$uriRetriever = $this->getUriRetriever();
117119
$contents = $this->uriRetriever->retrieve($resolvedUri);
118120
$this->confirmMediaType($uriRetriever);
@@ -207,7 +209,7 @@ public function resolve($uri, $baseUri = null)
207209
$components = $this->parse($uri);
208210
$path = $components['path'];
209211

210-
if ((array_key_exists('scheme', $components)) && ('http' === $components['scheme'])) {
212+
if (!empty($components['scheme'])) {
211213
return $uri;
212214
}
213215

tests/JsonSchema/Tests/Uri/UriRetrieverTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* file that was distributed with this source code.
88
*/
99

10-
namespace JsonSchema\Tests\Uri;
10+
namespace JsonSchema\Uri;
1111

1212
use JsonSchema\Validator;
1313

@@ -104,4 +104,20 @@ public function jsonProvider()
104104
array($childSchema, $parentSchema)
105105
);
106106
}
107+
108+
function testResolve() {
109+
$retriever = new UriRetriever();
110+
111+
$this->assertEquals('http://me.com/base/uri/foo.json' , $retriever->resolve('foo.json', 'http://me.com/base/uri/dir.json'));
112+
$this->assertEquals('https://mee.com/base/uri/foo.json' , $retriever->resolve('foo.json', 'https://mee.com/base/uri/dir.json'));
113+
$this->assertEquals('http://you.net/other-dir/foo.json' , $retriever->resolve('http://you.net/other-dir/foo.json', 'http://mee.com/base/uri/dir.json'));
114+
$this->assertEquals('https://you.net/other-dir/foo.json', $retriever->resolve('https://you.net/other-dir/foo.json', 'http:///base/uri/dir.json'));
115+
$this->assertEquals('https://you.net/other-dir/foo.json', $retriever->resolve('https://you.net/other-dir/foo.json', 'https:///base/uri/dir.json'));
116+
$this->assertEquals('file:///other-dir/foo.json' , $retriever->resolve('file:///other-dir/foo.json', 'file:///base/uri/dir.json'));
117+
118+
// question: query and fragmet are dropped. Is this the desired behaviour?
119+
$this->assertEquals('http://me.com/base/uri/foo.json' , $retriever->resolve('foo.json?query#fragment', 'http://me.com/base/uri/dir.json'));
120+
121+
}
122+
107123
}

0 commit comments

Comments
 (0)