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

Error page if url contains percentage, which happens on redirection with non ascii characters in url #32035

Open
its-mXc opened this issue Dec 2, 2021 · 9 comments
Labels
Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@its-mXc
Copy link

its-mXc commented Dec 2, 2021

What version of Next.js are you using?

12

What version of Node.js are you using?

12.22.0

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

next start

Describe the Bug

we get 400 Bad request if page contains "%", we also don't get error/issue on terminal it just compiles _error
image

This occurs because we are redirecting url's with non ascii characters, our page old-page/à becomes page/%E0

  return {
    redirect: {
      destination: `/page/${query?.id || ""}`,
      permanent: false,
    },
  };

I think while redirecting it is encoding url, so we get %. nevertheless it should not break i think

Expected Behavior

Redirect correctly, without changing url

To Reproduce

Open a url with %

@its-mXc its-mXc added the bug Issue was opened via the bug report template. label Dec 2, 2021
@balazsorban44 balazsorban44 added the Navigation Related to Next.js linking (e.g., <Link>) and navigation. label Dec 2, 2021
@its-mXc
Copy link
Author

its-mXc commented Dec 2, 2021

There is a weird case of it working for "%60", not sure why

@balazsorban44 balazsorban44 added kind: bug and removed bug Issue was opened via the bug report template. labels Jan 26, 2022
@balazsorban44
Copy link
Member

Just to verify since you left some details out, are you using something like the following?:

In pages/old-page/[id].jsx

...
export const getServerSideProps = async (ctx) => {
  return {
    redirect: {
      destination: `/page/${encodeURIComponent(ctx.query?.id || "")}`,
      permanent: false,
    },
  }
}

And then you have a page like pages/page/[id].jsx?

@its-mXc
Copy link
Author

its-mXc commented Jan 27, 2022

Hi @balazsorban44 , simplified version of what we are using

export async function getServerSideProps(context) {
  const { res, params, query } = context;

  return {
    redirect: {
      destination: `/page/${params?.courseid || ""}`,
      permanent: true,
    },
  };
}

Edit: Let me know if you need more info

Edit2: yes we have pages/page/[courseid].js. Is encodeURIComponent suggested ?

@its-mXc
Copy link
Author

its-mXc commented Jan 27, 2022

@balazsorban44 encodeURIComponent fixes the issue the url is not changed and loads correctly. Thank you so much

I am not sure whether to close the issue because %E0 as param directly which à was being converted to still breaks the page, even on invalid url or page example next-js url https://nextjs.org/%E0 or random like this https://nextjs.org/%E0G1

@timneutkens
Copy link
Member

Is this potentially related to #33763?

@its-mXc
Copy link
Author

its-mXc commented Jan 31, 2022

I will try to confirm this with new canary build this week @timneutkens

@its-mXc
Copy link
Author

its-mXc commented Jan 31, 2022

@timneutkens This issue is reproducible on 12.0.10-canary.1

I used sample nextjs application
npx create-next-app nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter"

Steps-

change version to 12.0.10-canary.1
Install and build
open url with %E0

image

image

@fcandi
Copy link

fcandi commented Apr 11, 2022

Thx, I experience exactly the same problem.

I just went live on vercel with Next 12.1.4. I use some basic rewrites and I also use the middleware example for international routing for prefixed default language.

You can check it here. Working URL:
https://geobla.com/en/campsite/devesa-gardens

Add a %, and there is a bad request error:
https://geobla.com/en/campsite/devesa-gardens%likeso

There is no log entry.

@1377sayaba
Copy link

I experience exactly the same problem with ?

@samcx samcx removed the kind: bug label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

No branches or pull requests

6 participants