Skip to content

bpo-32498: urllib.parse.unquote accepts bytes - #7768

Merged
taleinat merged 12 commits into
python:masterfrom
stein-k:unquote_handle_bytes
Oct 14, 2019
Merged

bpo-32498: urllib.parse.unquote accepts bytes#7768
taleinat merged 12 commits into
python:masterfrom
stein-k:unquote_handle_bytes

Conversation

@stein-k

@stein-k stein-k commented Jun 17, 2018

Copy link
Copy Markdown
Contributor

When calling urllib.parse.unquote with a bytes argument, the exception raised says: "a bytes-like object is required, not 'str'". This can be confusing as the user provided a bytes-like object.

The pull request changes urllib.parse.unquote to accept bytes as argument, and forwards the call to urllib.parse.unquote_to_bytes.

https://bugs.python.org/issue32498

@taleinat taleinat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_unquoting_with_bytes_input() requires some work.

  1. IMO there's no need to duplicate the part of test_unquoting() that checks all of the ASCII escape sequences. Even if this is kept, it should be refactored into a common helper rather than copy/pasted.
  2. If the above mentioned part is kept, it should actually test that quoted sequences are properly encoded! It currently just checking that unquoted characters are returned unchanged, which is missing the point.
  3. There should be a few explicit sanity tests where unquoted sequences are returned as-is.

Also (entirely optional), maybe add an example taken from an actual URL? I'd add this to test_unquote() too.

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@csabella

csabella commented Mar 2, 2019

Copy link
Copy Markdown
Contributor

Hi @stein-k, please take a look at the review by @taleinat and make the requested changes. Thanks!

@stein-k

stein-k commented Jul 13, 2019

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@taleinat taleinat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs must also be updated accordingly, including a "versionchanged" note about this being changed in version 3.9.

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@stein-k

stein-k commented Jul 28, 2019

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@matrixise matrixise self-assigned this Sep 14, 2019
@stein-k
stein-k requested a review from taleinat October 11, 2019 09:20

@taleinat taleinat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay in reviewing this! I have a few additional requests upon a final review, but after those this would be good to go.

Comment thread Doc/library/urllib.parse.rst Outdated
Comment thread Lib/test/test_urllib.py
"using unquote(): %r != %r" % (expect, result))

def test_unquoting_with_bytes_input(self):
given = b'bl\xc3\xa5b\xc3\xa6rsyltet\xc3\xb8y'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a simpler test case here in addition to the others. Also, please add a (short) comment explaining what each of the more complex test cases is checking.

@@ -0,0 +1,2 @@
Made ``urllib.parse.unquote()`` polymorphic, accepting both string and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"polymorphic" doesn't help clarity here; IMO just write "Made ... accept both str and bytes."

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@stein-k

stein-k commented Oct 13, 2019

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@bedevere-bot
bedevere-bot requested a review from taleinat October 13, 2019 18:03
@taleinat
taleinat merged commit aad2ee0 into python:master Oct 14, 2019
jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants