New submission from Chris Jerdonek <[email protected]>:
urllib.parse doesn't seem to round-trip file URI's containing multiple leading
slashes. For example, this--
import urllib.parse
def round_trip(url):
parsed = urllib.parse.urlsplit(url)
new_url = urllib.parse.urlunsplit(parsed)
print(f'{url} [{parsed}]\n{new_url}')
print('ROUNDTRIP: {}\n'.format(url == new_url))
for i in range(4):
round_trip('file://{}root/a'.format(i * '/'))
results in--
file://root/a [SplitResult(scheme='file', netloc='root', path='/a',
query='', fragment='')]
file://root/a
ROUNDTRIP: True
file:///root/a [SplitResult(scheme='file', netloc='', path='/root/a',
query='', fragment='')]
file:///root/a
ROUNDTRIP: True
file:////root/a [SplitResult(scheme='file', netloc='', path='//root/a',
query='', fragment='')]
file://root/a
ROUNDTRIP: False
file://///root/a [SplitResult(scheme='file', netloc='', path='///root/a',
query='', fragment='')]
file:///root/a
ROUNDTRIP: False
URI's of the form file:////<host>/<share>/<path> occur, for example, when one
wants to git-clone a UNC path on Windows:
https://stackoverflow.com/a/2520121/262819
Here is where CPython defines urlunsplit():
https://github.com/python/cpython/blob/4e11c461ed39085b8495a35c9367b46d8a0d306d/Lib/urllib/parse.py#L465-L482
(The '//' special-casing seems to occur in this line here:
https://github.com/python/cpython/blob/4e11c461ed39085b8495a35c9367b46d8a0d306d/Lib/urllib/parse.py#L473
)
And here is where the round-tripping is tested:
https://github.com/python/cpython/blob/4e11c461ed39085b8495a35c9367b46d8a0d306d/Lib/test/test_urlparse.py#L156
(Three initial leading slashes is tested, but not the problem case of four or
more.)
----------
components: Library (Lib)
messages: 322652
nosy: chris.jerdonek
priority: normal
severity: normal
status: open
title: urllib.parse doesn't round-trip file URI's with multiple leading slashes
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34276>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com