Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ def test_urlsplit_normalization(self):
with self.assertRaises(ValueError):
urlparse.urlsplit(url)

# check error message: invalid netloc must be formated with repr()
# to get an ASCII error message
with self.assertRaises(ValueError) as cm:
urlparse.urlsplit(u'http://example.com\uFF03@bing.com')
self.assertEqual(str(cm.exception),
"netloc u'example.com\\uff03@bing.com' contains invalid characters "
"under NFKC normalization")
self.assertIsInstance(cm.exception.args[0], str)

def test_main():
test_support.run_unittest(UrlParseTestCase)

Expand Down
5 changes: 3 additions & 2 deletions Lib/urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ def _checknetloc(netloc):
return
for c in '/?#@:':
if c in netloc2:
raise ValueError(u"netloc '" + netloc + u"' contains invalid " +
u"characters under NFKC normalization")
raise ValueError("netloc %r contains invalid characters "
"under NFKC normalization"
% netloc)

def urlsplit(url, scheme='', allow_fragments=True):
"""Parse a URL into 5 components:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`urlparse.urlsplit` error message for invalid ``netloc`` according to
NFKC normalization is now a :class:`str` string, rather than a
:class:`unicode` string, to prevent error when displaying the error.