Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/JsonSchema/Tool/Validator/UriValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function isValid(string $uri): bool

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

Expand Down
5 changes: 5 additions & 0 deletions tests/Tool/Validator/UriValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function validUriDataProvider(): \Generator
yield 'OASIS URN URI' => ['uri' => 'urn:oasis:names:specification:docbook:dtd:xml:4.1.2'];
yield 'Custom URI with underscore' => ['uri' => 'custom://reg_name/path/file.json'];
yield 'Custom URI with tilde' => ['uri' => 'custom://reg~name/path/file.json'];
yield 'File URI with implicit localhost (empty host)' => ['uri' => 'file:///path/to/file.txt'];
yield 'File URI with explicit host' => ['uri' => 'file://some-host/path/to/file.txt'];
yield 'File URI without any host' => ['uri' => 'file:/path/to/file.txt'];
}

public function invalidUriDataProvider(): \Generator
Expand All @@ -47,5 +50,7 @@ public function invalidUriDataProvider(): \Generator
yield 'Invalid path characters with "^"' => ['uri' => 'http://example.com/^invalid'];
yield 'Only mailto:' => ['uri' => 'mailto:'];
yield 'Invalid email used in mailto:' => ['uri' => 'mailto:user@.com'];
// Cannot be validated properly with regex only
// yield 'Invalid file uri (missing host)' => ['uri' => 'file://path/to/file.txt'];
Comment on lines +53 to +54
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove these lines as I would rather keep commented code out of the repo to keep it clean. Since there is no invalid file uri we can just skip this.

}
}