Skip to content

[2.7] bpo-36742: Fix urlparse.urlsplit() error message for Unicode URL#13937

Merged
vstinner merged 3 commits into
python:2.7from
vstinner:urlparse_str_errmsg
Jun 11, 2019
Merged

[2.7] bpo-36742: Fix urlparse.urlsplit() error message for Unicode URL#13937
vstinner merged 3 commits into
python:2.7from
vstinner:urlparse_str_errmsg

Conversation

@vstinner

@vstinner vstinner commented Jun 10, 2019

Copy link
Copy Markdown
Member

If urlparse.urlsplit() detects an invalid netloc according to NFKC
normalization, the error message type is now str rather than unicode,
and use repr() to format the URL, to prevent <exception str() failed>
when display the error message.

https://bugs.python.org/issue36742

If urlparse.urlsplit() detects an invalid netloc according to NFKC
normalization, the error message type is now str rather than unicode,
and use repr() to format the URL, to prevent <exception str() failed>
when display the error message.
@vstinner

Copy link
Copy Markdown
Member Author

This change fix the bug described at: https://bugs.python.org/issue36742#msg344981

Script:

import urlparse as urllib_parse
url = u'example.com\uFF03@bing.com'
url = u'http://\u30d5\u309a\ufe1380'
urllib_parse.urlsplit(url)

Output without the fix:

ValueError: <exception str() failed>

Output with the fix:

ValueError: netloc u'\u30d7:80' contains invalid characters under NFKC normalization

@vstinner

Copy link
Copy Markdown
Member Author

cc @stratakis @encukou

Comment thread Lib/test/test_urlparse.py Outdated

@orsenthil orsenthil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm.

@vstinner

Copy link
Copy Markdown
Member Author

cc @tirkarthi @zooba @gpshead

Comment thread Lib/urlparse.py Outdated
u"characters under NFKC normalization")
raise ValueError("netloc %r contains invalid characters "
"under NFKC normalization"
% netloc2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should netloc be reported in the error message? Python 3 and previous error messages report netloc.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh. You're right. I also fixed this bug and I updated the unit test to test this case.

@tirkarthi tirkarthi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks.

@vstinner vstinner merged commit 2b57847 into python:2.7 Jun 11, 2019
@vstinner vstinner deleted the urlparse_str_errmsg branch June 11, 2019 10:45
@vstinner

Copy link
Copy Markdown
Member Author

Thanks for review @tirkarthi and @orsenthil!

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.

5 participants