[New-bugs-announce] [issue40938] urllib.parse.urlunsplit makes relative path to absolute (http:g -> http:///g)
Open Close
report at bugs.python.org
Wed Jun 10 07:18:48 EDT 2020
New submission from Open Close <openandclose23 at gmail.com>:
path 'g' in 'http:g' becomes '/g'.
>>> urlsplit('http:g')
SplitResult(scheme='http', netloc='', path='g', query='', fragment='')
>>> urlunsplit(urlsplit('http:g'))
'http:///g'
>>> urlsplit('http:///g')
SplitResult(scheme='http', netloc='', path='/g', query='', fragment='')
>>> urljoin('http://a/b/c/d', 'http:g')
'http://a/b/c/g'
>>> urljoin('http://a/b/c/d', 'http:///g')
'http://a/g'
The problematic part of the code is:
def urlunsplit(components):
[...]
if netloc or (scheme and scheme in uses_netloc and url[:2] != '//'):
---> if url and url[:1] != '/': url = '/' + url
url = '//' + (netloc or '') + url
Note also that urllib has decided on the interpretation of 'http:g' (in test).
def test_RFC3986(self):
[...]
#self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser
self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') #relaxed parser
----------
messages: 371179
nosy: op368
priority: normal
severity: normal
status: open
title: urllib.parse.urlunsplit makes relative path to absolute (http:g -> http:///g)
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40938>
_______________________________________
More information about the New-bugs-announce
mailing list