Commit f61599b0 authored by Steve Dower's avatar Steve Dower Committed by GitHub

bpo-36742: Corrects fix to handle decomposition in usernames (GH-13812)

parent 74bede0d
...@@ -648,12 +648,13 @@ class UrlParseTestCase(unittest.TestCase): ...@@ -648,12 +648,13 @@ class UrlParseTestCase(unittest.TestCase):
urlparse.urlsplit(u'http://\u30d5\u309a\ufe1380') urlparse.urlsplit(u'http://\u30d5\u309a\ufe1380')
for scheme in [u"http", u"https", u"ftp"]: for scheme in [u"http", u"https", u"ftp"]:
for c in denorm_chars: for netloc in [u"netloc{}false.netloc", u"n{}user@netloc"]:
url = u"{}://netloc{}false.netloc/path".format(scheme, c) for c in denorm_chars:
if test_support.verbose: url = u"{}://{}/path".format(scheme, netloc.format(c))
print "Checking %r" % url if test_support.verbose:
with self.assertRaises(ValueError): print "Checking %r" % url
urlparse.urlsplit(url) with self.assertRaises(ValueError):
urlparse.urlsplit(url)
def test_main(): def test_main():
test_support.run_unittest(UrlParseTestCase) test_support.run_unittest(UrlParseTestCase)
......
...@@ -171,17 +171,17 @@ def _checknetloc(netloc): ...@@ -171,17 +171,17 @@ def _checknetloc(netloc):
# looking for characters like \u2100 that expand to 'a/c' # looking for characters like \u2100 that expand to 'a/c'
# IDNA uses NFKC equivalence, so normalize for this check # IDNA uses NFKC equivalence, so normalize for this check
import unicodedata import unicodedata
n = netloc.rpartition('@')[2] # ignore anything to the left of '@' n = netloc.replace(u'@', u'') # ignore characters already included
n = n.replace(':', '') # ignore characters already included n = n.replace(u':', u'') # but not the surrounding text
n = n.replace('#', '') # but not the surrounding text n = n.replace(u'#', u'')
n = n.replace('?', '') n = n.replace(u'?', u'')
netloc2 = unicodedata.normalize('NFKC', n) netloc2 = unicodedata.normalize('NFKC', n)
if n == netloc2: if n == netloc2:
return return
for c in '/?#@:': for c in '/?#@:':
if c in netloc2: if c in netloc2:
raise ValueError("netloc '" + netloc + "' contains invalid " + raise ValueError(u"netloc '" + netloc + u"' contains invalid " +
"characters under NFKC normalization") u"characters under NFKC normalization")
def urlsplit(url, scheme='', allow_fragments=True): def urlsplit(url, scheme='', allow_fragments=True):
"""Parse a URL into 5 components: """Parse a URL into 5 components:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment