Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The behaviour of encoded special characters in path params is not consistent between page.tsx and route.ts #64952

Open
dantman opened this issue Apr 24, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template.

Comments

@dantman
Copy link

dantman commented Apr 24, 2024

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/naughty-sinoussi-2cz5ks

To Reproduce

  1. Create a dynamic page.tsx route using a path parameter like /[pathParam]/ and {params}: {params: { pathParam: string }}
  2. Create a dynamic route.ts route using the same path parameter like /[pathParam]/ and {params}: {params: { pathParam: string }}
  3. Visit the page.tsx based route with special characters in the URL
  4. Visit the route.ts based route with special characters in the URL

Current vs. Expected behavior

I would expect Next.js' params object to behave the same whether it's used from page.tsx, route.ts, or useParams().

Instead pathParam is undecoded when used from page.tsx and useParams() but is decoded when used from route.ts.

/dynamic-page/%3F%2C%3D%2C%2F%2C%26%2Cшеллы

{
  "params": {
    "pathParam": "%3F%2C%3D%2C%2F%2C%26%2C%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"
  }
}

/dynamic-route/%3F%2C%3D%2C%2F%2C%26%2C%D1%88%D0%B5%D0%BB%D0%BB%D1%8B?

{
  "method": "GET",
  "params": {
    "pathParam": "?,=,/,&,шеллы"
  }
}

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
  Available memory (MB): 4102
  Available CPU cores: 2
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.2.0-canary.11 // There is a newer canary version (14.3.0-canary.21) available, please upgrade! 
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

@dantman dantman added the bug Issue was opened via the bug report template. label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

1 participant