Skip to content

Commit f61599b

Browse files
authored
bpo-36742: Corrects fix to handle decomposition in usernames (GH-13812)
1 parent 74bede0 commit f61599b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

Lib/test/test_urlparse.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,13 @@ def test_urlsplit_normalization(self):
648648
urlparse.urlsplit(u'http://\u30d5\u309a\ufe1380')
649649

650650
for scheme in [u"http", u"https", u"ftp"]:
651-
for c in denorm_chars:
652-
url = u"{}://netloc{}false.netloc/path".format(scheme, c)
653-
if test_support.verbose:
654-
print "Checking %r" % url
655-
with self.assertRaises(ValueError):
656-
urlparse.urlsplit(url)
651+
for netloc in [u"netloc{}false.netloc", u"n{}user@netloc"]:
652+
for c in denorm_chars:
653+
url = u"{}://{}/path".format(scheme, netloc.format(c))
654+
if test_support.verbose:
655+
print "Checking %r" % url
656+
with self.assertRaises(ValueError):
657+
urlparse.urlsplit(url)
657658

658659
def test_main():
659660
test_support.run_unittest(UrlParseTestCase)

Lib/urlparse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,17 @@ def _checknetloc(netloc):
171171
# looking for characters like \u2100 that expand to 'a/c'
172172
# IDNA uses NFKC equivalence, so normalize for this check
173173
import unicodedata
174-
n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
175-
n = n.replace(':', '') # ignore characters already included
176-
n = n.replace('#', '') # but not the surrounding text
177-
n = n.replace('?', '')
174+
n = netloc.replace(u'@', u'') # ignore characters already included
175+
n = n.replace(u':', u'') # but not the surrounding text
176+
n = n.replace(u'#', u'')
177+
n = n.replace(u'?', u'')
178178
netloc2 = unicodedata.normalize('NFKC', n)
179179
if n == netloc2:
180180
return
181181
for c in '/?#@:':
182182
if c in netloc2:
183-
raise ValueError("netloc '" + netloc + "' contains invalid " +
184-
"characters under NFKC normalization")
183+
raise ValueError(u"netloc '" + netloc + u"' contains invalid " +
184+
u"characters under NFKC normalization")
185185

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

0 commit comments

Comments
 (0)