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

Add a sortQueryParameters option #48

Merged

Conversation

IvanSanchez
Copy link
Contributor

normalize-url sorts query parameters by default, but that's a normalization that changes semantics, and is breaking some of my uses cases.

Thus, this PR adds a new option, sortQueryParameters, which defaults to true, plus unit tests.

@stevenvachon
Copy link

stevenvachon commented Jul 7, 2017

The sort algorithm only sorts the param names, and does not affect value order:

nomalizeUrl('http://host/?p1=value2&p2=value&p1=value1')
//-> http://host?p1=value2&p1=value1&p2=value

This should not affect any semantics and is almost spec-compliant (doesn't use code points).

@liweinan0423
Copy link

@stevenvachon sometimes we do not want the order of the query parameters to be changed. For example, when building a search result page, we ofter want to put the query parameter page=2 as the last parameter in the URL.

@sindresorhus sindresorhus merged commit b125e29 into sindresorhus:master Nov 30, 2017
@IvanSanchez IvanSanchez deleted the sort-query-parameters-option branch December 1, 2017 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants