]> 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:12:17 +0000 (17:12 +0300)
committerEzio Melotti <ezio.melotti@gmail.com>
Sat, 19 May 2012 14:12:17 +0000 (17:12 +0300)
Lib/test/test_urlparse.py
Lib/urlparse.py
Misc/NEWS

index 827282cedc0e7bc45c032f6dc18dba793c43f808..e484aafbc8d43444cd60596656a2203220520e88 100644 (file)
@@ -437,6 +437,13 @@ class UrlParseTestCase(unittest.TestCase):
         self.assertEqual(p.port, 80)
         self.assertEqual(p.geturl(), url)
 
+    def test_issue14072(self):
+        p1 = urlparse.urlsplit('tel:+31-641044153')
+        self.assertEqual(p1.scheme, 'tel')
+        self.assertEqual(p1.path, '+31-641044153')
+        p2 = urlparse.urlsplit('tel:+31641044153')
+        self.assertEqual(p2.scheme, 'tel')
+        self.assertEqual(p2.path, '+31641044153')
 
     def test_attributes_bad_port(self):
         """Check handling of non-integer ports."""
index 32eebe69bd412337a1532ee90fedf5377d409687..4c57725ce35fc1a0d6edae873a44669be169d18c 100644 (file)
@@ -185,12 +185,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 503e2f8052f861f15abcaf76d29fa4d807d81bcf..be559608ee7cce38e0b048caa2983aeb34626b22 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,9 @@ Library
 - Issue #14721: Send proper header, Content-length: 0 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.