Dec-28-2023, 10:04 AM
I am seeing unexpected behavior from the parse_qsl function when the query string parameter value is just '+'.
My Python version is 3.11. I am calling parse_qsl to parse query strings from URLs. It works as expected for normal parameter values, but returns an unexpected result when the value is '+'.
Here are some examples of what it returns for different queries:
I have searched the Python and urllib documentation but did not find any mention of this specific behavior. Can anyone explain why parse_qsl returns a space in this case, and if it is expected behavior defined somewhere? Or is this a bug in the implementation?
Any insight would be appreciated. Please let me know if you need any other context or details from me. I want to understand this parsing behavior better.
My Python version is 3.11. I am calling parse_qsl to parse query strings from URLs. It works as expected for normal parameter values, but returns an unexpected result when the value is '+'.
Here are some examples of what it returns for different queries:
from urllib.parse import parse_qsl parse_qsl('username=') # [] parse_qsl('username= ') # [('username', ' ')] parse_qsl('username=1+2') # [('username', '1 2')] parse_qsl('username=123') # [('username', '123')] parse_qsl('username=123&username=234') # [('username', '123'), ('username', '234')]However, when the value is just '+', it returns the tuple [('username', ' ')]:
parse_qsl('username=+') # [('username', ' ')]This seems strange to me, as '+' on its own does not represent a space. I would expect it to return [('username', '+')] or perhaps not parse it at all.
I have searched the Python and urllib documentation but did not find any mention of this specific behavior. Can anyone explain why parse_qsl returns a space in this case, and if it is expected behavior defined somewhere? Or is this a bug in the implementation?
Any insight would be appreciated. Please let me know if you need any other context or details from me. I want to understand this parsing behavior better.