Skip to content

Commit 0ceae23

Browse files
committed
bpo-27657: Fix urlparse() with numeric paths
Revert parsing decision from bpo-754016 in favor of the documented consensus in bpo-16932 of how to treat strings without a // to designate the netloc.
1 parent 13a6c09 commit 0ceae23

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

Lib/test/test_urlparse.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,15 +707,17 @@ def test_withoutscheme(self):
707707

708708
def test_portseparator(self):
709709
# Issue 754016 makes changes for port separator ':' from scheme separator
710-
self.assertEqual(urllib.parse.urlparse("path:80"),
711-
('','','path:80','','',''))
710+
self.assertEqual(urllib.parse.urlparse("http:80"), ('http','','80','','',''))
711+
self.assertEqual(urllib.parse.urlparse("https:80"), ('https','','80','','',''))
712+
self.assertEqual(urllib.parse.urlparse("path:80"), ('path','','80','','',''))
712713
self.assertEqual(urllib.parse.urlparse("http:"),('http','','','','',''))
713714
self.assertEqual(urllib.parse.urlparse("https:"),('https','','','','',''))
714715
self.assertEqual(urllib.parse.urlparse("http://www.python.org:80"),
715716
('http','www.python.org:80','','','',''))
716717
# As usual, need to check bytes input as well
717-
self.assertEqual(urllib.parse.urlparse(b"path:80"),
718-
(b'',b'',b'path:80',b'',b'',b''))
718+
self.assertEqual(urllib.parse.urlparse(b"http:80"), (b'http',b'',b'80',b'',b'',b''))
719+
self.assertEqual(urllib.parse.urlparse(b"https:80"), (b'https',b'',b'80',b'',b'',b''))
720+
self.assertEqual(urllib.parse.urlparse(b"path:80"), (b'path',b'',b'80',b'',b'',b''))
719721
self.assertEqual(urllib.parse.urlparse(b"http:"),(b'http',b'',b'',b'',b'',b''))
720722
self.assertEqual(urllib.parse.urlparse(b"https:"),(b'https',b'',b'',b'',b'',b''))
721723
self.assertEqual(urllib.parse.urlparse(b"http://www.python.org:80"),

Lib/urllib/parse.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,7 @@ def urlsplit(url, scheme='', allow_fragments=True):
426426
if c not in scheme_chars:
427427
break
428428
else:
429-
# make sure "url" is not actually a port number (in which case
430-
# "scheme" is really part of the path)
431-
rest = url[i+1:]
432-
if not rest or any(c not in '0123456789' for c in rest):
433-
# not a port number
434-
scheme, url = url[:i].lower(), rest
429+
scheme, url = url[:i].lower(), url[i+1:]
435430

436431
if url[:2] == '//':
437432
netloc, url = _splitnetloc(url, 2)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix urllib.parse.urlparse() with numeric paths. A string like "path:80" is
2+
no longer parsed as a path but as a scheme ("path") and a path ("80").

0 commit comments

Comments
 (0)