Skip to content

Commit 095373c

Browse files
vstinnerzooba
authored andcommitted
bpo-36742: Corrects fix to handle decomposition in usernames (GH-13812) (GH-13814) (#14772)
(cherry picked from commit 8d0ef0b) Co-authored-by: Steve Dower <steve.dower@python.org> (cherry picked from commit fd1771d)
1 parent 4d1c254 commit 095373c

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

996996
for scheme in ["http", "https", "ftp"]:
997-
for c in denorm_chars:
998-
url = "{}://netloc{}false.netloc/path".format(scheme, c)
999-
with self.subTest(url=url, char='{:04X}'.format(ord(c))):
1000-
with self.assertRaises(ValueError):
1001-
urllib.parse.urlsplit(url)
997+
for netloc in ["netloc{}false.netloc", "n{}user@netloc"]:
998+
for c in denorm_chars:
999+
url = "{}://{}/path".format(scheme, netloc.format(c))
1000+
with self.subTest(url=url, char='{:04X}'.format(ord(c))):
1001+
with self.assertRaises(ValueError):
1002+
urllib.parse.urlsplit(url)
10021003

10031004
class Utility_Tests(unittest.TestCase):
10041005
"""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
@@ -333,9 +333,9 @@ def _checknetloc(netloc):
333333
# looking for characters like \u2100 that expand to 'a/c'
334334
# IDNA uses NFKC equivalence, so normalize for this check
335335
import unicodedata
336-
n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
337-
n = n.replace(':', '') # ignore characters already included
338-
n = n.replace('#', '') # but not the surrounding text
336+
n = netloc.replace('@', '') # ignore characters already included
337+
n = n.replace(':', '') # but not the surrounding text
338+
n = n.replace('#', '')
339339
n = n.replace('?', '')
340340
netloc2 = unicodedata.normalize('NFKC', n)
341341
if n == netloc2:

0 commit comments

Comments
 (0)