theelous3 / asks

Async requests-like httplib for python.
MIT License
508 stars 63 forks source link

When encoding URLs, don't encode elements of iterables twice #156

Open poqoid opened 4 years ago

poqoid commented 4 years ago

Formerly, the code would run each element through quote_plus twice:

import asks
test_data = [{'foo': 'abc', 'bar': 'jkl'}, {'foo': ['abc def', 'ghi'], 'bar baz': 'jkl'}]

for row in test_data:
    print(asks.request_object.RequestProcessor._dict_to_query(row))
?foo=abc&bar=jkl
?foo=abc%252Bdef&foo=ghi&bar+baz=jkl

Note that %252B is + encoded twice:

>>> from urllib.parse import quote_plus
>>> quote_plus('+')
'%2B'
>>> quote_plus('%2B')
'%252B'

This pull request makes it so that each element is only encoded once.