Skip to content

URL comparison is order-based for query parameters #280

@LVerneyPEReN

Description

@LVerneyPEReN

Hi,

I am using boltons to do URL comparisons, being agnostic of the URL representation, and it works great so far except for query parameters.

Typically, with percent encoding, this is working as expected:

>>> a = boltons.urlutils.URL('http://example.com/foo, bar')
>>> b = boltons.urlutils.URL('http://example.com/foo%2C%20bar')
>>> a == b
True

However, when taking query parameters into account, the comparison seems to be ordered (while I would expect the order of query parameters to have no impact). See:

>>> a = boltons.urlutils.URL('http://example.com/foo, bar?foo=bar&bar=foo')
>>> b = boltons.urlutils.URL('http://example.com/foo%2C%20bar?bar=foo&foo=bar')
>>> a == b
False

I solved the issue with a bit of monkey patching, but is there a reason for having an ordered comparison here?

My solution:

def query_params_dict_eq_monkey_patch(self, other):
    """
    >>> a = boltons.urlutils.URL('http://example.com/foo, bar?foo=bar&bar=foo')
    >>> b = boltons.urlutils.URL('http://example.com/foo%2C%20bar?bar=foo&foo=bar')
    >>> a == b
    True
    """
    return dict(self) == dict(other)
boltons.urlutils.QueryParamDict.__eq__ = query_params_dict_eq_monkey_patch

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions