]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36742: Fixes handling of pre-normalization characters in urlsplit() (GH-13017...
authorSteve Dower <steve.dower@python.org>
Sun, 14 Jul 2019 08:16:19 +0000 (10:16 +0200)
committerlarryhastings <larry@hastings.org>
Sun, 14 Jul 2019 08:16:19 +0000 (10:16 +0200)
Lib/test/test_urlparse.py
Lib/urllib/parse.py
Misc/NEWS.d/next/Security/2019-04-29-15-34-59.bpo-36742.QCUY0i.rst [new file with mode: 0644]

index d0420b0e742de6b58e060fddf7886b504e6c8025..1e90e18609b2f9c1a7161d8782dd2ba79fbfbe7a 100644 (file)
@@ -987,6 +987,12 @@ class UrlParseTestCase(unittest.TestCase):
         self.assertIn('\u2100', denorm_chars)
         self.assertIn('\uFF03', denorm_chars)
 
+        # bpo-36742: Verify port separators are ignored when they
+        # existed prior to decomposition
+        urllib.parse.urlsplit('http://\u30d5\u309a:80')
+        with self.assertRaises(ValueError):
+            urllib.parse.urlsplit('http://\u30d5\u309a\ufe1380')
+
         for scheme in ["http", "https", "ftp"]:
             for c in denorm_chars:
                 url = "{}://netloc{}false.netloc/path".format(scheme, c)
index 7ba2b445f5cdb8bcdd6c2d2154d5a03071a4e7b9..7405d660fc4e26c464b08e3003eb84d5890a6038 100644 (file)
@@ -333,13 +333,16 @@ def _checknetloc(netloc):
     # looking for characters like \u2100 that expand to 'a/c'
     # IDNA uses NFKC equivalence, so normalize for this check
     import unicodedata
-    netloc2 = unicodedata.normalize('NFKC', netloc)
-    if netloc == netloc2:
+    n = netloc.rpartition('@')[2] # ignore anything to the left of '@'
+    n = n.replace(':', '')        # ignore characters already included
+    n = n.replace('#', '')        # but not the surrounding text
+    n = n.replace('?', '')
+    netloc2 = unicodedata.normalize('NFKC', n)
+    if n == netloc2:
         return
-    _, _, netloc = netloc.rpartition('@') # anything to the left of '@' is okay
     for c in '/?#@:':
         if c in netloc2:
-            raise ValueError("netloc '" + netloc2 + "' contains invalid " +
+            raise ValueError("netloc '" + netloc + "' contains invalid " +
                              "characters under NFKC normalization")
 
 def urlsplit(url, scheme='', allow_fragments=True):
diff --git a/Misc/NEWS.d/next/Security/2019-04-29-15-34-59.bpo-36742.QCUY0i.rst b/Misc/NEWS.d/next/Security/2019-04-29-15-34-59.bpo-36742.QCUY0i.rst
new file mode 100644 (file)
index 0000000..d729ed2
--- /dev/null
@@ -0,0 +1 @@
+Fixes mishandling of pre-normalization characters in urlsplit().