mirror of
https://github.com/python/cpython.git
synced 2025-08-06 18:08:48 +00:00
[3.12] GH-126766: url2pathname()
: handle empty authority section. (GH-126767) (#126837)
GH-126766: `url2pathname()`: handle empty authority section. (GH-126767)
Discard two leading slashes from the beginning of a `file:` URI if they
introduce an empty authority section. As a result, file URIs like
`///etc/hosts` are correctly parsed as `/etc/hosts`.
(cherry picked from commit cae9d9d20f
)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
306db142c2
commit
04f38bb775
4 changed files with 14 additions and 9 deletions
|
@ -19,10 +19,9 @@ def url2pathname(url):
|
|||
url = url.replace(':', '|')
|
||||
if not '|' in url:
|
||||
# No drive specifier, just convert slashes
|
||||
if url[:4] == '////':
|
||||
# path is something like ////host/path/on/remote/host
|
||||
# convert this to \\host\path\on\remote\host
|
||||
# (notice halving of slashes at the start of the path)
|
||||
if url[:3] == '///':
|
||||
# URL has an empty authority section, so the path begins on the
|
||||
# third character.
|
||||
url = url[2:]
|
||||
# make sure not to convert quoted slashes :-)
|
||||
return urllib.parse.unquote(url.replace('/', '\\'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue