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

Skip to content

Commit 397eb44

Browse files
committed
Issue #11467: Fix urlparse behavior when handling urls which contains scheme specific part only digits.
1 parent 20f53f1 commit 397eb44

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

Lib/test/test_urlparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ def test_RFC1808(self):
197197
#self.checkJoin(RFC1808_BASE, 'http:g', 'http:g')
198198
#self.checkJoin(RFC1808_BASE, 'http:', 'http:')
199199

200+
def test_RFC2368(self):
201+
# Issue 11467: path that starts with a number is not parsed correctly
202+
self.assertEqual(urllib.parse.urlparse('mailto:[email protected]'),
203+
('mailto', '', '[email protected]', '', '', ''))
204+
200205
def test_RFC2396(self):
201206
# cases from RFC 2396
202207
self.checkJoin(RFC2396_BASE, 'g:h', 'g:h')

Lib/urllib/parse.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,17 @@ def urlsplit(url, scheme='', allow_fragments=True):
184184
v = SplitResult(scheme, netloc, url, query, fragment)
185185
_parse_cache[key] = v
186186
return v
187-
if url.endswith(':') or not url[i+1].isdigit():
188-
for c in url[:i]:
189-
if c not in scheme_chars:
190-
break
191-
else:
187+
for c in url[:i]:
188+
if c not in scheme_chars:
189+
break
190+
else:
191+
try:
192+
# make sure "url" is not actually a port number (in which case
193+
# "scheme" is really part of the path
194+
_testportnum = int(url[i+1:])
195+
except ValueError:
192196
scheme, url = url[:i].lower(), url[i+1:]
197+
193198
if url[:2] == '//':
194199
netloc, url = _splitnetloc(url, 2)
195200
if allow_fragments and scheme in uses_fragment and '#' in url:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ Core and Builtins
5151
Library
5252
-------
5353

54+
- Issue #11467: Fix urlparse behavior when handling urls which contains scheme
55+
specific part only digits. Patch by Santoso Wijaya.
56+
5457
- Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows.
5558
Patch by Santoso Wijaya.
5659

0 commit comments

Comments
 (0)