Skip to content

[BUG] URL in middleware has decoded parameters #533

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

Closed
SamyPesse opened this issue Apr 5, 2025 · 3 comments · Fixed by opennextjs/opennextjs-aws#817
Closed

[BUG] URL in middleware has decoded parameters #533

SamyPesse opened this issue Apr 5, 2025 · 3 comments · Fixed by opennextjs/opennextjs-aws#817
Labels
bug Something isn't working triage

Comments

@SamyPesse
Copy link
Contributor

Describe the bug

When logging request.url in the middleware, or accessing a query parameter with new URL(request.url).searchParams.get('something'), the returned value is URL-decoded when it should not

For example loading https://deployedapp.com/?something=General%2520Banner would log 2 different things:

The following code:

export async function middleware(request: NextRequest) {
  console.log(new URL(request.url).searchParams.get('something'));
}

On Vercel or locally: General%20Banner (as expected)

With OpenNext: General Banner (the value is decoded twice).

Steps to reproduce

  1. Log new URL(request.url).searchParams.get('something') in a middleware
  2. Open a URL like https://deployedapp.com/?something=General%2520Banner where the parameter something is encoded twice (ex: when passing a URL as a query param)
  3. Notice it logs a different value on OpenNext vs Next

Expected behavior

Both should log the value value `General%20Banner``

@opennextjs/cloudflare version

1.0.0-beta.0

Wrangler version

3.112.0

next info output

Not relevant to this problem

Additional context

I think the problem comes from these lines https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/core/routing/util.ts#L134-L136

@SamyPesse SamyPesse added bug Something isn't working triage labels Apr 5, 2025
@conico974
Copy link
Collaborator

Good catch, we'll need to revert this one partially opennextjs/opennextjs-aws#603.
I'll have to check if it doesn't break the other part of the PR though

@SamyPesse
Copy link
Contributor Author

@conico974 should I open an issue in opennextjs-aws?

@conico974
Copy link
Collaborator

@SamyPesse Yeah you can do that, i've started working on this here opennextjs/opennextjs-aws#817, but it doesn't seem to be enough.
I'll need to dig deeper into this to figure out what's going on here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants