Skip to content

Commit dfbcc82

Browse files
committed
[BUGFIX] Don't resolve a schema id against itself (#452)
* Don't resolve a schema id against itself * Add test for double-resolve bugfix
1 parent b80053b commit dfbcc82

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/JsonSchema/SchemaStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function expandRefs(&$schema, $base = null)
9292
return;
9393
}
9494

95-
if (property_exists($schema, 'id') && is_string($schema->id)) {
95+
if (property_exists($schema, 'id') && is_string($schema->id) && $base != $schema->id) {
9696
$base = $this->uriResolver->resolve($schema->id, $base);
9797
}
9898

tests/SchemaStorageTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,25 @@ public function testMetaSchemaFixes()
302302
$this->assertEquals('uri-reference', $draft_03->properties->{'$ref'}->format);
303303
$this->assertEquals('uri-reference', $draft_04->properties->id->format);
304304
}
305+
306+
public function testNoDoubleResolve()
307+
{
308+
$schemaOne = json_decode('{"id": "test/schema", "$ref": "../test2/schema2"}');
309+
310+
$uriRetriever = $this->prophesize('JsonSchema\UriRetrieverInterface');
311+
$uriRetriever->retrieve('test/schema')->willReturn($schemaOne)->shouldBeCalled();
312+
313+
$s = new SchemaStorage($uriRetriever->reveal());
314+
$schema = $s->addSchema('test/schema');
315+
316+
$r = new \ReflectionObject($s);
317+
$p = $r->getProperty('schemas');
318+
$p->setAccessible(true);
319+
$schemas = $p->getValue($s);
320+
321+
$this->assertEquals(
322+
'file://' . getcwd() . '/test2/schema2#',
323+
$schemas['test/schema']->{'$ref'}
324+
);
325+
}
305326
}

0 commit comments

Comments
 (0)