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

Query parameters not compared independent of order #288

Closed
linuxdaemon opened this issue Feb 14, 2019 · 4 comments
Closed

Query parameters not compared independent of order #288

linuxdaemon opened this issue Feb 14, 2019 · 4 comments

Comments

@linuxdaemon
Copy link

In a majority of cases URL('http://example.com/?foo=bar&test=1') should be equivalent to URL('http://example.com/?test=1&foo=bar'), but they are treated as unique and there does not seem to be any extra methods for an order-independent comparison. I've had to do something similar to url.with_query(MultiDict(sorted(url.query.items()))) to both URL objects before comparing them.

A method on the URL object to do this sort of comparison would be quite useful, or maybe even implementing it in the normal comparison methods.

@aio-libs-bot
Copy link

GitMate.io thinks possibly related issues are #245 (Query parameters didn't get fully encoded), #34 (Incorrect parsing of query parameters with %3B (;) inside), #73 (Unexpected compare behaviour), #33 (Parse URL parameter), and #102 (Document encoded parameter).

@asvetlov
Copy link
Member

By the standard, order or query values does matter.
Moreover, URL('http://example.com/?foo=bar&foo=baz') and URL('http://example.com/?foo=baz&foo=bar') are different URLs.
The default behavior should be not changed.

If sorting by order works for you -- that's fine. You can do it manually without the library modification.
If you want to propose a new comparison method -- please elaborate the new API first. How should it look like?

@linuxdaemon
Copy link
Author

I was thinking a method like URL.unify() to 'unify' the URL format by converting it to a standard form, with like empty or default url components either always added or always removed, ensuring a consistent order with the parameters, stuff like that. My main use case for this so far is in testing a function which generates a URL with query parameters formed from a dict, as testing on different python versions produces different orders.

@asvetlov
Copy link
Member

I'm sorry, but URL.unify() is out of the project scope.
You can write a helper for dict sorting in your project easy though.

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

No branches or pull requests

3 participants