diff --git a/src/JsonSchema/Tool/Validator/RelativeReferenceValidator.php b/src/JsonSchema/Tool/Validator/RelativeReferenceValidator.php index fd95f7bf..79fede0d 100644 --- a/src/JsonSchema/Tool/Validator/RelativeReferenceValidator.php +++ b/src/JsonSchema/Tool/Validator/RelativeReferenceValidator.php @@ -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; } } diff --git a/tests/Tool/Validator/RelativeReferenceValidatorTest.php b/tests/Tool/Validator/RelativeReferenceValidatorTest.php index 7b46e232..9894e682 100644 --- a/tests/Tool/Validator/RelativeReferenceValidatorTest.php +++ b/tests/Tool/Validator/RelativeReferenceValidatorTest.php @@ -26,6 +26,12 @@ 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' => '?#']; + yield 'Empty query and fragment' => ['ref' => '?#fragment']; + yield 'Query and fragment' => ['ref' => '?query#fragment']; } public function invalidRelativeReferenceDataProvider(): \Generator @@ -33,8 +39,5 @@ 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' => '?']; } }