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
13 changes: 7 additions & 6 deletions Lib/test/test_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,13 @@ def test_urlsplit_normalization(self):
urlparse.urlsplit(u'http://\u30d5\u309a\ufe1380')

for scheme in [u"http", u"https", u"ftp"]:
for c in denorm_chars:
url = u"{}://netloc{}false.netloc/path".format(scheme, c)
if test_support.verbose:
print "Checking %r" % url
with self.assertRaises(ValueError):
urlparse.urlsplit(url)
for netloc in [u"netloc{}false.netloc", u"n{}user@netloc"]:
for c in denorm_chars:
url = u"{}://{}/path".format(scheme, netloc.format(c))
if test_support.verbose:
print "Checking %r" % url
with self.assertRaises(ValueError):
urlparse.urlsplit(url)

def test_main():
test_support.run_unittest(UrlParseTestCase)
Expand Down
12 changes: 6 additions & 6 deletions Lib/urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ def _checknetloc(netloc):
# looking for characters like \u2100 that expand to 'a/c'
# IDNA uses NFKC equivalence, so normalize for this check
import unicodedata
n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
n = n.replace(':', '') # ignore characters already included
n = n.replace('#', '') # but not the surrounding text
n = n.replace('?', '')
n = netloc.replace(u'@', u'') # ignore characters already included
n = n.replace(u':', u'') # but not the surrounding text
n = n.replace(u'#', u'')
n = n.replace(u'?', u'')
netloc2 = unicodedata.normalize('NFKC', n)
if n == netloc2:
return
for c in '/?#@:':
if c in netloc2:
raise ValueError("netloc '" + netloc + "' contains invalid " +
"characters under NFKC normalization")
raise ValueError(u"netloc '" + netloc + u"' contains invalid " +
u"characters under NFKC normalization")

def urlsplit(url, scheme='', allow_fragments=True):
"""Parse a URL into 5 components:
Expand Down