Skip to content

Conversation

@MazenSamehR
Copy link

@MazenSamehR MazenSamehR commented Nov 30, 2025

fixes: #920

Summary

  • adds isXsdAnyURI, covering XML Schema anyURI requirements (whitespace collapse, percent-encoding, RFC 3986 validation, IPv6/IPvFuture authority parsing)
  • wires the validator into src/index.js and documents usage in README.md
  • introduces extensive tests for valid/invalid absolute and relative references, malformed authorities, percent-encoding errors, and encodeURI failure scenarios

References

Checklist

  • PR contains only changes related; no stray files, etc.
  • README updated (where applicable)
  • Tests written (where applicable)
  • References provided in PR (where applicable)

@codecov
Copy link

codecov bot commented Nov 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f605a9c) to head (2e14b32).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MazenSamehR MazenSamehR changed the title Add XSD anyURI validator and tests feat(isXsdAnyURI): add XML Schema anyURI validator Nov 30, 2025
@MazenSamehR
Copy link
Author

@WikiRik Can you please review this PR?

@rubiin rubiin requested review from WikiRik and Copilot December 4, 2025 15:45
Copilot finished reviewing on behalf of rubiin December 4, 2025 15:50
Copy link

Copilot AI left a 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) {
Copy link

Copilot AI Dec 4, 2025

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.

Suggested change
if (Number.isNaN(portNumber) || portNumber > 65535) {
if (Number.isNaN(portNumber) || portNumber < 1 || portNumber > 65535) {

Copilot uses AI. Check for mistakes.
Copy link
Author

@MazenSamehR MazenSamehR Dec 4, 2025

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?

Comment on lines +1050 to +1080
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',
],
});
Copy link

Copilot AI Dec 4, 2025

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.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Need validation for XSD:AnyURI types

1 participant