Skip to content

api.URLSearchParams.sort - Encoded parameters' values get decoded and viceversa #43595

@TPacini0

Description

@TPacini0

What type of issue is this?

Other

What information was incorrect, unhelpful, or incomplete?

I can’t find any description of how the sorting algorithm handles search parameters' values, or whether they are encoded or decoded using a specific encoding.

What browsers does this problem apply to, if applicable?

Node.js

What did you expect to see?

Expectation:

When applying the sort() function to search parameters, I expect the parameters to be sorted while their values remain unchanged.

Reality:

When applying the sort() function, the parameters are sorted, but their values are modified: special characters are percent-encoded, while already percent-encoded characters are decoded.

Is this expected behavior? I reviewed the WHATWG specification but could not find a clear explanation.

Did you test this? If so, how?

const u = new URL('/api?user=user1&password=a b!', 'https://www.domain.com')

// u.href: https://www.domain.com/api?user=user1&password=a%20b!
// u.search: ?user=user1&password=a%20b!

u.searchParams.sort();

// u.href: https://www.domain.com/api?password=a+b%21&user=user1
// u.search: ?password=a+b%21&user=user1

The parameters are sorted but password value is modified.

Can you link to any release notes, bugs, pull requests, or MDN pages related to this?

No response

Do you have anything more you want to share?

No response

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/sort

MDN metadata

MDN page report details
  • Query: api.URLSearchParams.sort
  • Report started: 2026-03-27T10:00:57.879Z

Metadata

Metadata

Assignees

No one assigned

    Labels

    Content:WebAPIWeb API docsneeds triageTriage needed by staff and/or partners. Automatically applied when an issue is opened.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions