niksite/url-normalize

Query parameter order not preserved

nvllsvm opened this issue · 7 comments

It's possible for the order of parameters in the query string to be unnecessarily alerted by url_normalize.url_normalize.

Consider this example (Python 2.7 and Python 3.7):

import url_normalize
URL = 'http://example.com/?2=A&1=b&C=D&2=0'
print(URL)
print(url_normalize.url_normalize(URL))

Executing with url_normalize 1.3.3 preserves the query string:

http://example.com/?2=A&1=b&C=D&2=0
http://example.com/?2=A&1=b&C=D&2=0

With url_normalize 1.4.0 onward, the order is unnecessarily altered:

http://example.com/?2=A&1=b&C=D&2=0
http://example.com/?1=b&2=0&2=A&C=D

@nvllsvm
Came across the same issue.
Any work around you got ?

@dhirajforyou I've hard pinned to 1.3.3.

@nvllsvm
thanks, it solves.

Also,


Not able to understand why authors introduce sorting on get params ?
Authors, your inputs please.

If you want to have a consistent normalization, regardless of the input order, sorting the attributes is a good idea. At least, in my use case, the idea is to have my link resources as unique as possible; where http://example.com/?2=A&1=b&C=D&2=0 is equivalent to http://example.com/?C=D&2=0&2=A&1=b

@wimmuskee Thanks a lot for your insights and inputs.
I got your point.
Can we have this as flag based, defaulting to sort( as you mentioned) ?

Can I raise a pull request for this ?

The sort_query_params optional param has been added to the 1.4.2 version:

>>> from url_normalize import url_normalize
>>> url_normalize('http://example.com/?b=1&a=2')
'http://example.com/?a=2&b=1'
>>> url_normalize('http://example.com/?b=1&a=2', sort_query_params=False)
'http://example.com/?b=1&a=2