Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6709b7d

Browse files
committed
#14072: Fix parsing of tel URIs in urlparse by making the check for ports stricter.
1 parent 5fa4a89 commit 6709b7d

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

Lib/test/test_urlparse.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,13 @@ def test_quote_errors(self):
806806
encoding='utf-8')
807807
self.assertRaises(TypeError, urllib.parse.quote, b'foo', errors='strict')
808808

809+
def test_issue14072(self):
810+
p1 = urllib.parse.urlsplit('tel:+31-641044153')
811+
self.assertEqual(p1.scheme, 'tel')
812+
self.assertEqual(p1.path, '+31-641044153')
813+
p2 = urllib.parse.urlsplit('tel:+31641044153')
814+
self.assertEqual(p2.scheme, 'tel')
815+
self.assertEqual(p2.path, '+31641044153')
809816

810817
def test_main():
811818
support.run_unittest(UrlParseTestCase)

Lib/urllib/parse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ def urlsplit(url, scheme='', allow_fragments=True):
338338
if c not in scheme_chars:
339339
break
340340
else:
341-
try:
342-
# make sure "url" is not actually a port number (in which case
343-
# "scheme" is really part of the path
344-
_testportnum = int(url[i+1:])
345-
except ValueError:
346-
scheme, url = url[:i].lower(), url[i+1:]
341+
# make sure "url" is not actually a port number (in which case
342+
# "scheme" is really part of the path)
343+
rest = url[i+1:]
344+
if not rest or any(c not in '0123456789' for c in rest):
345+
# not a port number
346+
scheme, url = url[:i].lower(), rest
347347

348348
if url[:2] == '//':
349349
netloc, url = _splitnetloc(url, 2)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ Library
6666
- Issue #14721: Send the correct 'Content-length: 0' header when the body is an
6767
empty string ''. Initial Patch contributed by Arve Knudsen.
6868

69+
- Issue #14072: Fix parsing of 'tel' URIs in urlparse by making the check for
70+
ports stricter.
71+
6972
- Issue #9374: Generic parsing of query and fragment portions of url for any
7073
scheme. Supported both by RFC3986 and RFC2396.
7174

0 commit comments

Comments
 (0)