-
-
Couldn't load subscription status.
- Fork 326
Description
Description
In v4.2.0, a feature was introduced to encode the pathname before sending it over to Next.js routing. However, if a dynamic path param contains a /, it is treated as a path separator instead of a value of the param and not encoded in the URL, leading to a different page. If the param value is encoded before passing to next-intl, the resulting URL contains double encoded characters.
Verifications
- I've verified that the problem I'm experiencing isn't covered in the docs.
- I've searched for similar, existing issues on GitHub and Stack Overflow.
- I've compared my app to a working example to look for differences.
Mandatory reproduction URL
https://github.com/SteffenAuer/next-intl-encoding-issue
Reproduction description
Steps to reproduce:
- Open reproduction
- There's three links. All attempt to point to
/en/test/[param]with the param value beingFoo / Bar %- No encoding on my end, passing that param value above straight to next-intl
Link - Encoded the param value before passing it to next-intl
Link - Regular
atag with manually built pathname. This is the expected value
- No encoding on my end, passing that param value above straight to next-intl
- Notice the issue: The first link leads to a 404, the second and third link lead to the correct page. However, the second link contains double encoded values (e.g. instead of
%2Ffor a/, it has%252F: The%from the encoded/is encoded again)
Expected behaviour
The expected href is the one of the third link on the reproduction page. There should be no encoding necessary before passing the param values to next-intl.
I believe this is the issue:
next-intl/packages/next-intl/src/navigation/shared/utils.tsx
Lines 209 to 212 in 081d952
| return pathname | |
| .split('/') | |
| .map((segment) => encodeURIComponent(segment)) | |
| .join('/'); |
/, the params should be encoded individually before being applied to the template. It should not assume that the param values don't contain / characters.