Skip to content

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

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

Merged
merged 3 commits into from
Jun 11, 2019
Merged

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

merged 3 commits into from
Jun 11, 2019

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jun 10, 2019

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
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
Member Author

cc @stratakis @encukou

Copy link
Member

@orsenthil orsenthil left a comment

Choose a reason for hiding this comment

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

lgtm.

@vstinner
Copy link
Member Author

cc @tirkarthi @zooba @gpshead

Lib/urlparse.py Outdated
u"characters under NFKC normalization")
raise ValueError("netloc %r contains invalid characters "
"under NFKC normalization"
% netloc2)
Copy link
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
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.

Copy link
Member

@tirkarthi tirkarthi left a comment

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
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