Skip to content

Don't crash router on malformed percent-encoded params (#3440)#4302

Open
BigBalli wants to merge 1 commit intojashkenas:masterfrom
BigBalli:fix-3440-decode-error
Open

Don't crash router on malformed percent-encoded params (#3440)#4302
BigBalli wants to merge 1 commit intojashkenas:masterfrom
BigBalli:fix-3440-decode-error

Conversation

@BigBalli
Copy link
Copy Markdown

@BigBalli BigBalli commented Apr 6, 2026

Fixes #3440.

Problem

Route parameters are decoded with decodeURIComponent, which throws
URIError for malformed sequences (e.g. /search/malformed%query).
The exception bubbles out of _extractParameters, aborts route
matching entirely, and prevents the application from gracefully
handling a bad URL — which is especially painful for search-style
routes whose values often come from external sources.

Fix

Wrap the decodeURIComponent call in a try/catch in
_extractParameters. On URIError, fall back to the raw, undecoded
parameter value so the route still matches and the handler still runs.
The application is then free to detect and recover (e.g. show a "bad
query" message). Other exceptions are re-thrown unchanged.

Test

Added a regression test exercising _extractParameters directly with
a malformed %query parameter. npm run lint passes.

A URL like /search/malformed%query causes decodeURIComponent to throw
URIError, which previously aborted route matching entirely and
prevented the application from handling the bad URL gracefully.

Catch URIError in _extractParameters and fall back to the raw,
undecoded value for that parameter. The route still matches, the
handler still runs, and the app can decide how to recover.
Other exceptions are re-thrown unchanged.
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.

Invalid parameters

1 participant