-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat(isXsdAnyURI): add XML Schema anyURI validator #2636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2636 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 114 115 +1
Lines 2567 2736 +169
Branches 651 690 +39
==========================================
+ Hits 2567 2736 +169 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@WikiRik Can you please review this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new validator isXsdAnyURI that validates strings against the XML Schema anyURI type specification, which defers to RFC 3986 for URI syntax rules. The implementation handles the full complexity of URI validation including schemes, authorities (with IPv6 and IPvFuture support), paths, queries, fragments, and percent-encoding, while also implementing XML Schema-specific whitespace collapsing.
Key changes:
- Implements comprehensive URI/IRI validation per RFC 3986 with XML Schema whitespace handling
- Adds support for both absolute and relative URI references, including edge cases like fragment-only and query-only references
- Includes extensive test coverage for valid URIs (schemes, IPv6, relative paths, etc.) and invalid cases (malformed ports, invalid percent-encoding, disallowed characters)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/lib/isXsdAnyURI.js | New validator implementation with RFC 3986 URI parsing, XML whitespace collapse, authority/path/query/fragment validation, and special handling for IPv6 addresses |
| src/index.js | Integrates the new validator into the main exports, maintaining alphabetical order |
| README.md | Documents the new validator with description and link to W3C specification |
| test/validators.test.js | Adds comprehensive test cases covering valid URIs (various schemes, IPv6, relative references) and invalid URIs (bad ports, malformed syntax, forbidden characters) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| const portNumber = parseInt(port, 10); | ||
|
|
||
| if (Number.isNaN(portNumber) || portNumber > 65535) { |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Port 0 should be rejected as invalid. The validation currently only checks if portNumber > 65535 but should also check if portNumber < 1. Port 0 is reserved and not a valid port number for actual use.
Suggested fix:
if (Number.isNaN(portNumber) || portNumber < 1 || portNumber > 65535) {
return false;
}Note: The existing isURL validator in this codebase also validates port <= 0 at line 241 of src/lib/isURL.js.
| if (Number.isNaN(portNumber) || portNumber > 65535) { | |
| if (Number.isNaN(portNumber) || portNumber < 1 || portNumber > 65535) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rubiin I think for anyURI we aim to validate RFC 3986 syntax rather than protocol-specific semantics. RFC 3986 only requires that the port be digits; it doesn’t forbid 0. So Should we strictly follow the schema definition, or block it because it's technically invalid for network connections?
| invalid: [ | ||
| 'http://example.com:99999', | ||
| 'http://example.com:port', | ||
| 'http://example.com:-1', | ||
| 'http://[::1', | ||
| 'http://example.com#frag#extra', | ||
| 'foo%zz', | ||
| 'foo%2', | ||
| 'http://user@:8080', | ||
| 'http://user[info@example.com', | ||
| '\\server\\share', | ||
| 'http://example.com/pa|th', | ||
| 'http://example.com/path\u0006', | ||
| '//:8080/path', | ||
| 'http:///path', | ||
| 'file://user@', | ||
| 'http://example.com/%', | ||
| 'foo#frag%2', | ||
| 'http://example.com/%ZZ', | ||
| 'http://example.com/?q=abc^123', | ||
| 'http://example.com?foo[bar', | ||
| 'foo://?query', | ||
| 'foo%2/bar', | ||
| 'http://[::g]/path', | ||
| 'http://[::1]foo', | ||
| 'http://host:80:123/path', | ||
| 'http://exa[mple.com', | ||
| 'http://example.com/\ud800', | ||
| 'foo<bar', | ||
| ], | ||
| }); |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for port 0 validation. Since port 0 is invalid (reserved), there should be a test case like 'http://example.com:0' in the invalid array to ensure port 0 is properly rejected once the validation bug is fixed.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
fixes: #920
Summary
isXsdAnyURI, covering XML SchemaanyURIrequirements (whitespace collapse, percent-encoding, RFC 3986 validation, IPv6/IPvFuture authority parsing)src/index.jsand documents usage inREADME.mdReferences
Checklist