Skip to content

[BUG] URL in middleware has decoded parameters #533

Closed
opennextjs/opennextjs-aws
#817
@SamyPesse

Description

@SamyPesse

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions