Skip to content

Path Param Encoding doesn't respect "/" in params #2014

@SteffenAuer

Description

@SteffenAuer

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

Mandatory reproduction URL

https://github.com/SteffenAuer/next-intl-encoding-issue

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. There's three links. All attempt to point to /en/test/[param] with the param value being Foo / Bar %
    1. No encoding on my end, passing that param value above straight to next-intl Link
    2. Encoded the param value before passing it to next-intl Link
    3. Regular a tag with manually built pathname. This is the expected value
  3. 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 %2F for 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:

return pathname
.split('/')
.map((segment) => encodeURIComponent(segment))
.join('/');
. Instead of encoding the entire pathname split at /, the params should be encoded individually before being applied to the template. It should not assume that the param values don't contain / characters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingunconfirmedNeeds triage.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions