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
bpo-38567: Handle bytes as input to urllib.parse.unquote_plus #16903
base: main
Are you sure you want to change the base?
Conversation
Test non-ascii input as bytes.
@@ -734,6 +734,10 @@ def unquote_plus(string, encoding='utf-8', errors='replace'): | |||
|
|||
unquote_plus('%7e/abc+def') -> '~/abc def' | |||
""" | |||
if isinstance(string, bytes): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the documentation https://docs.python.org/3/library/urllib.parse.html?highlight=urllib#urllib.parse.unquote_plus string
must be a str
type.
If you need parse bytes you must use unquote_to_bytes
. IMO here you need prove if
string is a str
if !isinstance(string, str):
raise TypeError ('a str object is required')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think handling both bytes and str would make it more like unquote in 3.9 (https://docs.python.org/3.9/library/urllib.parse.html?highlight=urllib#urllib.parse.unquote).
I would expect them to behave the same and accept the same types.
I hope the comments I made to the proposed changes could be reviewed. The changes would make the urllib.parse API more consistent. |
Handle bytes as input to unquote_plus
https://bugs.python.org/issue38567