Skip to content

Commit 250b62a

Browse files
bpo-36742: Corrects fix to handle decomposition in usernames (GH-13812)
(cherry picked from commit 8d0ef0b) Co-authored-by: Steve Dower <[email protected]>
1 parent 12c1787 commit 250b62a

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
@@ -1008,11 +1008,12 @@ def test_urlsplit_normalization(self):
10081008
urllib.parse.urlsplit('http://\u30d5\u309a\ufe1380')
10091009

10101010
for scheme in ["http", "https", "ftp"]:
1011-
for c in denorm_chars:
1012-
url = "{}://netloc{}false.netloc/path".format(scheme, c)
1013-
with self.subTest(url=url, char='{:04X}'.format(ord(c))):
1014-
with self.assertRaises(ValueError):
1015-
urllib.parse.urlsplit(url)
1011+
for netloc in ["netloc{}false.netloc", "n{}user@netloc"]:
1012+
for c in denorm_chars:
1013+
url = "{}://{}/path".format(scheme, netloc.format(c))
1014+
with self.subTest(url=url, char='{:04X}'.format(ord(c))):
1015+
with self.assertRaises(ValueError):
1016+
urllib.parse.urlsplit(url)
10161017

10171018
class Utility_Tests(unittest.TestCase):
10181019
"""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
@@ -397,9 +397,9 @@ def _checknetloc(netloc):
397397
# looking for characters like \u2100 that expand to 'a/c'
398398
# IDNA uses NFKC equivalence, so normalize for this check
399399
import unicodedata
400-
n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
401-
n = n.replace(':', '') # ignore characters already included
402-
n = n.replace('#', '') # but not the surrounding text
400+
n = netloc.replace('@', '') # ignore characters already included
401+
n = n.replace(':', '') # but not the surrounding text
402+
n = n.replace('#', '')
403403
n = n.replace('?', '')
404404
netloc2 = unicodedata.normalize('NFKC', n)
405405
if n == netloc2:

0 commit comments

Comments
 (0)