python / cpython

The Python programming language
https://www.python.org
Other
62.29k stars 29.93k forks source link

parse_qsl does not decode parameters well #101934

Closed PAvel00m closed 1 year ago

PAvel00m commented 1 year ago

When trying to parse a query string

parse_qsl("limit=12&next=eyJsYXN0X2lkIjo1OTgyMDM3MDE2NzQ0LCJsYXN0X3ZhbHVlIjoiQm9sbGUgc2VuemEgZnJvbnRpZXJlIChBdXJvcmEtYmlvZHluYW1pZSnwn5C48J+QuPCfkLgifQ==")

I get: [('limit', '12'), ('next', 'eyJsYXN0X2lkIjo1OTgyMDM3MDE2NzQ0LCJsYXN0X3ZhbHVlIjoiQm9sbGUgc2VuemEgZnJvbnRpZXJlIChBdXJvcmEtYmlvZHluYW1pZSnwn5C48J QuPCfkLgifQ==')]

at the end of the parameter value the parser has replaced the + sign with a space.

`eyJsYXN0X2lkIjo1OTgyMDM3MDE2NzQ0LCJsYXN0X3ZhbHVlIjoiQm9sbGUgc2VuemEgZnJvbnRpZXJlIChBdXJvcmEtYmlvZHluYW1pZSnwn5C48J+QuPCfkLgifQ==

not equal

eyJsYXN0X2lkIjo1OTgyMDM3MDE2NzQ0LCJsYXN0X3ZhbHVlIjoiQm9sbGUgc2VuemEgZnJvbnRpZXJlIChBdXJvcmEtYmlvZHluYW1pZSnwn5C48J QuPCfkLgifQ==`

Python 3.10 Mac OS

arhadthedev commented 1 year ago

@orsenthil (as an urllib expert)

ericvsmith commented 1 year ago

For those not in the know, parse_qsl is in urllib.parse.

The standard https://www.w3.org/TR/html401/interact/forms.html says that when encoding, spaces are replaced by plus signs. When parsing, the reverse happens.

The behavior in parse_sql is deliberate, there are tests for it.

ericvsmith commented 1 year ago

Here's a simpler example:

>>> import urllib.parse
>>> urllib.parse.parse_qsl("a=b+c")
[('a', 'b c')]
PAvel00m commented 1 year ago

For those not in the know, parse_qsl is in urllib.parse.

The standard https://www.w3.org/TR/html401/interact/forms.html says that when encoding, spaces are replaced by plus signs. When parsing, the reverse happens.

The behavior in parse_sql is deliberate, there are tests for it.

Thanks