Skip to content

fix: percent-decode route params extracted from the pathname#223

Merged
uhyo merged 1 commit into
masterfrom
claude/issue-206-pathname-decoding-25bujm
Jul 12, 2026
Merged

fix: percent-decode route params extracted from the pathname#223
uhyo merged 1 commit into
masterfrom
claude/issue-206-pathname-decoding-25bujm

Conversation

@uhyo

@uhyo uhyo commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Closes #206

Problem

Navigating to /users/Jo%C3%A3o with path: "/users/:name" yielded params.name === "Jo%C3%A3o" instead of "João". URLPattern.exec() matches against the percent-encoded pathname (location.pathname is always in encoded form) and returns group values as-is, so any param containing spaces, unicode, or reserved characters reached loaders, actions, and components percent-encoded.

Fix

  • extractParams in packages/router/src/core/matchRoutes.ts now decodes each group value with decodeURIComponent, falling back to the raw value for malformed sequences (e.g. a lone %) rather than failing the match. All matching paths (exact, fast prefix, and backtracking) funnel through extractParams, so merged parent params are covered too.
  • consumedPathname intentionally stays encoded — it is used to slice the remaining pathname for child matching.
  • Since the input pathname is guaranteed to be in encoded form, decoding here cannot double-decode.

Tests & docs

  • Added tests for unicode decoding, spaces/reserved characters, params inherited from parent routes, and the malformed-sequence fallback.
  • Documented the decoding behavior in the Route Parameters section of the Getting Started docs page.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B1GkQiKvX1SHpFs9ojyj1m


Generated by Claude Code

URLPattern matches against the encoded pathname and returns group values
as-is, so params like /users/Jo%C3%A3o reached components and loaders in
percent-encoded form. Decode each param value with decodeURIComponent,
falling back to the raw value for malformed sequences.

Closes #206

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B1GkQiKvX1SHpFs9ojyj1m
@uhyo
uhyo merged commit a5f67b2 into master Jul 12, 2026
1 check passed
@uhyo
uhyo deleted the claude/issue-206-pathname-decoding-25bujm branch July 12, 2026 00:48
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.

Route params are not percent-decoded

2 participants