Skip to content

Commit 6bd7bf9

Browse files
authored
Merge pull request #49 from martinhartmann/master
Proper URL decoding on file:/// references
2 parents 964038c + a88a570 commit 6bd7bf9

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/RemoteRef/BasicFetcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class BasicFetcher implements RemoteRefProvider
88
{
99
public function getSchemaData($url)
1010
{
11-
return json_decode(file_get_contents($url));
11+
return json_decode(file_get_contents(rawurldecode($url)));
1212
}
13-
}
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"integer": {
3+
"type": "integer"
4+
},
5+
"refToInteger": {
6+
"$ref": "#/integer"
7+
},
8+
"indirectRefToInteger": {
9+
"allOf": [
10+
{},
11+
{
12+
"$ref": "#/refToInteger"
13+
}
14+
]
15+
},
16+
"refToExternalInteger": {
17+
"$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
18+
}
19+
}

tests/src/PHPUnit/Ref/FileResolverTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ function testFileReferenceRealpath()
113113
$schema->in('abc');
114114
}
115115

116+
function testFileReferenceRealpathWithSpecialCharacters()
117+
{
118+
$pathToExternalSchema = realpath(__DIR__ . '/../../../resources/remotes/#special~characters%directory/subSchemas.json');
119+
$pathToExternalSchema = str_replace('#special~characters%directory', rawurlencode('#special~characters%directory'), $pathToExternalSchema);
120+
$schemaData = json_decode(<<<JSON
121+
{"\$ref": "file://$pathToExternalSchema#/integer"}
122+
JSON
123+
);
124+
125+
$schema = Schema::import($schemaData);
126+
$schema->in(123);
127+
128+
$this->setExpectedException(get_class(new InvalidValue()));
129+
$schema->in('abc');
130+
}
131+
116132
function testFileReferenceNoProtocolScheme()
117133
{
118134
$pathToExternalSchema = __DIR__ . '/../../../resources/remotes/subSchemas.json';

0 commit comments

Comments
 (0)