diff --git a/CHANGELOG.md b/CHANGELOG.md index 67fffbc7..824690ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Allow underscore and tilde in URI hostnames as per RFC 3986 ([#853](https://github.com/jsonrainbow/json-schema/pull/853)) ## [6.6.1] - 2025-11-07 ### Changed diff --git a/src/JsonSchema/Tool/Validator/UriValidator.php b/src/JsonSchema/Tool/Validator/UriValidator.php index b761f91f..c5e2cf6e 100644 --- a/src/JsonSchema/Tool/Validator/UriValidator.php +++ b/src/JsonSchema/Tool/Validator/UriValidator.php @@ -12,7 +12,7 @@ public static function isValid(string $uri): bool $hierarchicalPattern = '/^ ([a-z][a-z0-9+\-.]*):\/\/ # Scheme (http, https, ftp, etc.) (?:([^:@\/?#]+)(?::([^@\/?#]*))?@)? # Optional userinfo (user:pass@) - ([a-z0-9.-]+|\[[a-f0-9:.]+\]) # Hostname or IPv6 in brackets + ([a-z0-9._~-]+|\[[a-f0-9:.]+\]) # Hostname or IPv6 in brackets (?::(\d{1,5}))? # Optional port (\/[a-zA-Z0-9._~!$&\'()*+,;=:@\/%-]*)* # Path (valid characters only) (\?([^#]*))? # Optional query diff --git a/tests/Tool/Validator/UriValidatorTest.php b/tests/Tool/Validator/UriValidatorTest.php index 13e99b85..7eedaca8 100644 --- a/tests/Tool/Validator/UriValidatorTest.php +++ b/tests/Tool/Validator/UriValidatorTest.php @@ -32,6 +32,8 @@ public function validUriDataProvider(): \Generator yield 'Data URI' => ['uri' => 'data:text/plain;charset=utf-8,Hello%20World!']; yield 'ISBN URN URI' => ['uri' => 'urn:isbn:0451450523']; 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']; } public function invalidUriDataProvider(): \Generator