Don't throw on malformed percent-encoding in userinfo - #243
Open
hikmetba-bit wants to merge 1 commit into
Open
hikmetba-bit wants to merge 1 commit into
hikmetba-bit wants to merge 1 commit into
Conversation
The constructor and set('auth', ...) called encodeURIComponent(
decodeURIComponent(x)) on username/password with no guard, so a stray
'%' (or any invalid percent-escape) in the userinfo propagated a raw
URIError out of new Url(...) / set(...).
This contradicts url-parse's documented tolerant-parser design (unshiftio#195)
and diverges from the WHATWG URL parser, which accepts the same input
without throwing.
Add a decode() helper that falls back to the raw (still-encoded) input
on URIError, and use it at all six username/password call sites in the
constructor and set('auth'). Invalid input still round-trips safely
(re-encoded rather than decoded), it just no longer throws.
Fixes unshiftio#242.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #242.
The constructor and
set('auth', ...)callencodeURIComponent(decodeURIComponent(x))on username/password with no guard, so a stray%(or any invalid percent-escape) in the userinfo propagates a rawURIErrorout ofnew Url(...)/set(...).This contradicts url-parse's documented tolerant-parser design (see #195: "url-parse was designed to not throw errors like the legacy Node.js URL parser"), and diverges from the WHATWG
URLparser, which accepts the same input without throwing.Fix
Added a
decode()helper that falls back to the raw (still-encoded) input onURIError, and used it at all six username/password call sites in the constructor andset('auth', ...). Invalid input still round-trips safely — it gets re-encoded rather than decoded (e.g.'%'becomes'%25') — it just no longer throws.Testing
http://%@example.com/,http://user:%@example.com/) andset('auth', '%').URIErroragainst the code without this fix, and passes with it.npm test(full mocha suite + c8 coverage): 102 passing, coverage unchanged at 100% statements / 100% lines / 100% functions.🤖 Generated with Claude Code