Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/JsonSchema/Tool/Validator/RelativeReferenceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ public static function isValid(string $ref): bool
return false; // Spaces are not allowed in URIs
}

if (preg_match('/^\?#|^#$/', $ref)) {
return false; // Missing path but having query and fragment
}

if ($ref === '#' || $ref === '?') {
return false; // Missing path and having only fragment or query
}

return true;
}
}
9 changes: 6 additions & 3 deletions tests/Tool/Validator/RelativeReferenceValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ public function validRelativeReferenceDataProvider(): \Generator
yield 'Relative path from root' => ['ref' => '/relative/path'];
yield 'Relative path up one level' => ['ref' => '../up-one-level'];
yield 'Relative path from current' => ['ref' => 'foo/bar'];
yield 'Empty fragment (RFC 3986: path-empty + fragment)' => ['ref' => '#'];
yield 'Fragment only' => ['ref' => '#section'];
yield 'Empty query (RFC 3986: path-empty + query)' => ['ref' => '?'];
yield 'Empty query and empty fragment' => ['ref' => '?#'];
Comment thread
DannyvdSluijs marked this conversation as resolved.
yield 'Empty query and fragment' => ['ref' => '?#fragment'];
yield 'Query and fragment' => ['ref' => '?query#fragment'];
}

public function invalidRelativeReferenceDataProvider(): \Generator
{
yield 'Absolute URI' => ['ref' => 'http://example.com'];
yield 'Three slashes' => ['ref' => '///three/slashes'];
yield 'Path with spaces' => ['ref' => '/path with spaces'];
yield 'No path having query and fragment' => ['ref' => '?#invalid'];
yield 'Missing path having fragment' => ['ref' => '#'];
yield 'Missing path having query' => ['ref' => '?'];
}
}
Loading