Skip to content

fix: handle malformed URNs without throwing - #211

Merged
Tony133 merged 3 commits into
mainfrom
fix/malformed-urn-no-throw
Aug 18, 2026
Merged

fix: handle malformed URNs without throwing#211
Tony133 merged 3 commits into
mainfrom
fix/malformed-urn-no-throw

Conversation

@mcollina

Copy link
Copy Markdown
Member

Normalize and equal now treat an ordinary URN that fails scheme-specific parsing (a missing nid) as malformed input instead of surfacing an uncaught URN without nid cannot be serialized error.

  • normalize preserves the original malformed string unchanged
  • equal returns false instead of throwing
  • resolve rejects the malformed scheme-specific input with a clear URI is malformed. error

This is the follow-up to the URN parsing anchoring in #203, which now rejects more malformed inputs and so exposed the throw path. A new malformedSchemeSpecific status flag is threaded through the status-carrying helpers (parseWithStatus, normalizeStringWithStatus, normalizeComparableURI, resolve).

Normalize and equal now treat an ordinary URN that fails scheme-specific
parsing (missing nid) as malformed input: normalize preserves the original
string unchanged and equal returns false, instead of surfacing an uncaught
'URN without nid cannot be serialized' error. Resolve rejects the malformed
scheme-specific input with a clear error.

This is the follow-up to the URN parsing anchoring in #203, which now
rejects more malformed inputs and so exposed the throw path.

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! A small, non-blocking suggestion: it might be worth adding a test that calls resolve() with an invalid URN to check the actual error message, since that path is currently only covered indirectly. What do you think?

@mcollina

Copy link
Copy Markdown
Member Author

Implemented Tony's suggestion: added a resolve handles malformed ordinary URNs without throwing test in test/malformed-urn.test.js that directly calls resolve() with each malformed URN (as both a relative reference and a base URI), asserting it does not throw and preserves the malformed scheme-specific input.

Note: resolve() does not actually raise a URI is malformed. error for malformed URNs — it preserves the input, which matches upstream uri-js. The new test locks in that actual behavior so the path is covered directly rather than only indirectly.

@Tony133

Tony133 commented Aug 17, 2026

Copy link
Copy Markdown
Member

There are conflicts in the malformed-urn.test.js file

…throw

# Conflicts:
#	test/malformed-urn.test.js
@Tony133
Tony133 merged commit 6e3eb54 into main Aug 18, 2026
44 checks passed
@Tony133
Tony133 deleted the fix/malformed-urn-no-throw branch August 18, 2026 07:53
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.

2 participants