]> granicus.if.org Git - python/commitdiff
#14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
authorEzio Melotti <ezio.melotti@gmail.com>
Sat, 19 May 2012 14:15:19 +0000 (17:15 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 19 May 2012 14:15:19 +0000 (17:15 +0300)
Lib/test/test_urlparse.py
Lib/urllib/parse.py
Misc/NEWS

index 578438159d802e35b80af305e5166c0f166c639d..73150cffa65a0f54a8e8fb3368e7ad57506901b9 100755 (executable)
@@ -806,6 +806,13 @@ class UrlParseTestCase(unittest.TestCase):
                           encoding='utf-8')
         self.assertRaises(TypeError, urllib.parse.quote, b'foo', errors='strict')
 
+    def test_issue14072(self):
+        p1 = urllib.parse.urlsplit('tel:+31-641044153')
+        self.assertEqual(p1.scheme, 'tel')
+        self.assertEqual(p1.path, '+31-641044153')
+        p2 = urllib.parse.urlsplit('tel:+31641044153')
+        self.assertEqual(p2.scheme, 'tel')
+        self.assertEqual(p2.path, '+31641044153')
 
 def test_main():
     support.run_unittest(UrlParseTestCase)
index 47b7962662a39374129b591e8b79e5cc04412c9f..92170ad0a2435907ab06f6e3404dccdad1986869 100644 (file)
@@ -338,12 +338,12 @@ def urlsplit(url, scheme='', allow_fragments=True):
             if c not in scheme_chars:
                 break
         else:
-            try:
-                # make sure "url" is not actually a port number (in which case
-                # "scheme" is really part of the path
-                _testportnum = int(url[i+1:])
-            except ValueError:
-                scheme, url = url[:i].lower(), url[i+1:]
+            # make sure "url" is not actually a port number (in which case
+            # "scheme" is really part of the path)
+            rest = url[i+1:]
+            if not rest or any(c not in '0123456789' for c in rest):
+                # not a port number
+                scheme, url = url[:i].lower(), rest
 
     if url[:2] == '//':
         netloc, url = _splitnetloc(url, 2)
index 4cbea2463a9a6bdb17cde86aca55d5721ff269fa..ead1bbf26b8bf05b066311ff97a0fcb93e88abe1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,9 @@ Library
 - Issue #14721: Send the correct 'Content-length: 0' header when the body is an
   empty string ''. Initial Patch contributed by Arve Knudsen.
 
+- Issue #14072: Fix parsing of 'tel' URIs in urlparse by making the check for
+  ports stricter.
+
 - Issue #9374: Generic parsing of query and fragment portions of url for any
   scheme. Supported both by RFC3986 and RFC2396.