Skip to content

fix: Keep $ patterns in route param values literally - #2406

Merged
amannn merged 2 commits into
amannn:mainfrom
soroush5:fix/dollar-sign-route-params
Sep 10, 2026
Merged

amannn merged 2 commits into
amannn:mainfrom
soroush5:fix/dollar-sign-route-params

Conversation

@soroush5

Copy link
Copy Markdown
Contributor

Fixes #2405.

Route param values containing $ replacement patterns ($&, $', $`, $1) were interpreted by String.replace, corrupting localized URLs from the navigation APIs (getPathname, Link, redirect, useRouter) and from middleware localized-pathname redirects. With $& the placeholder was re-inserted and compileLocalizedPathname even threw Insufficient params provided.

Both substitution sites now pass a replacer function so values are inserted verbatim. Regression tests added in navigation/shared/utils.test.tsx and middleware/utils.test.tsx.

Verification: full next-intl suite 899/899 green, tsc --noEmit, ESLint and Prettier clean.

Route param values containing `$` replacement patterns (e.g. `$&`,
$', $`, $1) were interpreted by `String.replace`, corrupting
localized URLs produced by the navigation APIs (`getPathname`, `Link`,
`redirect`, `useRouter`) and by middleware localized-pathname
redirects. In the worst case (`$&`) the placeholder was re-inserted and
`compileLocalizedPathname` threw 'Insufficient params provided'.

Pass a replacer function so param values are always inserted verbatim.
@vercel

vercel Bot commented Sep 10, 2026

Copy link
Copy Markdown

@soroush5 is attempting to deploy a commit to the next-intl Team on Vercel.

A member of the Team first needs to authorize it.

The replacer function added in this PR grows the brotlied bundle
by 4 B, from 3155 B to 3159 B.

Co-Authored-By: Claude Opus 5 <[email protected]>
@vercel

vercel Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
next-intl-docs Ready Ready Preview Sep 10, 2026 7:41am UTC
next-intl-example-app-router Ready Ready Preview Sep 10, 2026 7:41am UTC
next-intl-example-app-router-without-i18n-routing Ready Ready Preview Sep 10, 2026 7:41am UTC

Request Review

@amannn amannn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks a lot!

@amannn
amannn merged commit a97b35e into amannn:main Sep 10, 2026
6 checks passed
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 param values containing $ patterns corrupt localized URLs (or throw)

2 participants