churchyard / rpms / python3

Forked from rpms/python3 6 years ago
Clone

Blame 00320-fix-pre-normalization-chars-in-urlsplit.patch

1b92cc7
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
1b92cc7
index 0faf2bb..d0365ec 100644
1b92cc7
--- a/Lib/test/test_urlparse.py
1b92cc7
+++ b/Lib/test/test_urlparse.py
1b92cc7
@@ -1011,6 +1011,12 @@ class UrlParseTestCase(unittest.TestCase):
1b92cc7
         self.assertIn('\u2100', denorm_chars)
1b92cc7
         self.assertIn('\uFF03', denorm_chars)
1b92cc7
 
1b92cc7
+        # bpo-36742: Verify port separators are ignored when they
1b92cc7
+        # existed prior to decomposition
1b92cc7
+        urllib.parse.urlsplit('http://\u30d5\u309a:80')
1b92cc7
+        with self.assertRaises(ValueError):
1b92cc7
+            urllib.parse.urlsplit('http://\u30d5\u309a\ufe1380')
1b92cc7
+
1b92cc7
         for scheme in ["http", "https", "ftp"]:
1b92cc7
             for c in denorm_chars:
1b92cc7
                 url = "{}://netloc{}false.netloc/path".format(scheme, c)
1b92cc7
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
1b92cc7
index 8b6c9b1..e2f7b69 100644
1b92cc7
--- a/Lib/urllib/parse.py
1b92cc7
+++ b/Lib/urllib/parse.py
1b92cc7
@@ -402,13 +402,16 @@ def _checknetloc(netloc):
1b92cc7
     # looking for characters like \u2100 that expand to 'a/c'
1b92cc7
     # IDNA uses NFKC equivalence, so normalize for this check
1b92cc7
     import unicodedata
1b92cc7
-    netloc2 = unicodedata.normalize('NFKC', netloc)
1b92cc7
-    if netloc == netloc2:
1b92cc7
+    n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
1b92cc7
+    n = n.replace(':', '')        # ignore characters already included
1b92cc7
+    n = n.replace('#', '')        # but not the surrounding text
1b92cc7
+    n = n.replace('?', '')
1b92cc7
+    netloc2 = unicodedata.normalize('NFKC', n)
1b92cc7
+    if n == netloc2:
1b92cc7
         return
1b92cc7
-    _, _, netloc = netloc.rpartition('@') # anything to the left of '@' is okay
1b92cc7
     for c in '/?#@:':
1b92cc7
         if c in netloc2:
1b92cc7
-            raise ValueError("netloc '" + netloc2 + "' contains invalid " +
1b92cc7
+            raise ValueError("netloc '" + netloc + "' contains invalid " +
1b92cc7
                              "characters under NFKC normalization")
1b92cc7
 
1b92cc7
 def urlsplit(url, scheme='', allow_fragments=True):