Skip to content

Commit 8d0ef0b

Browse files
zoobaambv
authored andcommitted
bpo-36742: Corrects fix to handle decomposition in usernames (#13812)
1 parent 800d786 commit 8d0ef0b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Lib/test/test_urlparse.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,12 @@ def test_urlsplit_normalization(self):
10181018
urllib.parse.urlsplit('http://\u30d5\u309a\ufe1380')
10191019

10201020
for scheme in ["http", "https", "ftp"]:
1021-
for c in denorm_chars:
1022-
url = "{}://netloc{}false.netloc/path".format(scheme, c)
1023-
with self.subTest(url=url, char='{:04X}'.format(ord(c))):
1024-
with self.assertRaises(ValueError):
1025-
urllib.parse.urlsplit(url)
1021+
for netloc in ["netloc{}false.netloc", "n{}user@netloc"]:
1022+
for c in denorm_chars:
1023+
url = "{}://{}/path".format(scheme, netloc.format(c))
1024+
with self.subTest(url=url, char='{:04X}'.format(ord(c))):
1025+
with self.assertRaises(ValueError):
1026+
urllib.parse.urlsplit(url)
10261027

10271028
class Utility_Tests(unittest.TestCase):
10281029
"""Testcase to test the various utility functions in the urllib."""

Lib/urllib/parse.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ def _checknetloc(netloc):
402402
# looking for characters like \u2100 that expand to 'a/c'
403403
# IDNA uses NFKC equivalence, so normalize for this check
404404
import unicodedata
405-
n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
406-
n = n.replace(':', '') # ignore characters already included
407-
n = n.replace('#', '') # but not the surrounding text
405+
n = netloc.replace('@', '') # ignore characters already included
406+
n = n.replace(':', '') # but not the surrounding text
407+
n = n.replace('#', '')
408408
n = n.replace('?', '')
409409
netloc2 = unicodedata.normalize('NFKC', n)
410410
if n == netloc2:

0 commit comments

Comments
 (0)