Skip to content

Double Encoding of Query Parameters #2482

@lacherogwu

Description

@lacherogwu

Reproduction

https://stackblitz.com/edit/vitejs-vite-qjvsopux

Steps to reproduce the bug

Description

When pushing a query using the vue-router, I've observed inconsistent encoding behavior: query parameters are either encoded twice or not at all.

Example

Consider the following code snippet:

const router = useRouter();

router.push({
  query: { notEncoded: '{name}', encoded: encodeURIComponent('{name}') },
});

The resulting URL appears as:

/?notEncoded={name}&encoded=%257Bname%257D
  • The notEncoded parameter remains unchanged, as expected.
  • The encoded parameter, however, is encoded twice.

For reference, the expected single encoding result is:

console.log(encodeURIComponent('{name}')); // %7Bname%7D

But in the URL, it appears as %257Bname%257D, indicating double encoding.

Reproduction

You can reproduce this issue using the following Stackblitz project.

Expected behavior

/?notEncoded={name}&encoded=%7Bname%7D

Actual behavior

/?notEncoded={name}&encoded=%257Bname%257D

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions