Skip to content

Commit 07afbe1

Browse files
committed
file schema fixes
- expand uri validator tests - treat file as non-hierarchical
1 parent 134e989 commit 07afbe1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/JsonSchema/Tool/Validator/UriValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function isValid(string $uri): bool
2121

2222
// RFC 3986: Non-Hierarchical URIs (mailto, data, urn, news)
2323
$nonHierarchicalPattern = '/^
24-
(mailto|data|urn|news|tel): # Only allow known non-hierarchical schemes
24+
(mailto|data|urn|news|tel|file): # Only allow known non-hierarchical schemes
2525
(.+) # Must contain at least one character after scheme
2626
$/ix';
2727

tests/Tool/Validator/UriValidatorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function validUriDataProvider(): \Generator
3434
yield 'OASIS URN URI' => ['uri' => 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'];
3535
yield 'Custom URI with underscore' => ['uri' => 'custom://reg_name/path/file.json'];
3636
yield 'Custom URI with tilde' => ['uri' => 'custom://reg~name/path/file.json'];
37+
yield 'File URI with implicit localhost (empty host)' => ['uri' => 'file:///path/to/file.txt'];
38+
yield 'File URI with explicit host' => ['uri' => 'file://some-host/path/to/file.txt'];
39+
yield 'File URI without any host' => ['uri' => 'file:/path/to/file.txt'];
3740
}
3841

3942
public function invalidUriDataProvider(): \Generator
@@ -47,5 +50,7 @@ public function invalidUriDataProvider(): \Generator
4750
yield 'Invalid path characters with "^"' => ['uri' => 'http://example.com/^invalid'];
4851
yield 'Only mailto:' => ['uri' => 'mailto:'];
4952
yield 'Invalid email used in mailto:' => ['uri' => 'mailto:[email protected]'];
53+
// Cannot be validated properly with regex only
54+
// yield 'Invalid file uri (not enough slashes)' => ['uri' => 'file://path/to/file.txt'];
5055
}
5156
}

0 commit comments

Comments
 (0)