diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-11-14 20:22:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-14 20:22:14 (GMT) |
commit | cae9d9d20f61cdbde0765efa340b6b596c31b67f (patch) | |
tree | 72fd81537fbe2b3989fbaf3f952ad8c65da7d0f7 /Lib/nturl2path.py | |
parent | 47cbf038850852cdcbe7a404ed7c64542340d58a (diff) | |
download | cpython-cae9d9d20f61cdbde0765efa340b6b596c31b67f.zip cpython-cae9d9d20f61cdbde0765efa340b6b596c31b67f.tar.gz cpython-cae9d9d20f61cdbde0765efa340b6b596c31b67f.tar.bz2 |
GH-126766: `url2pathname()`: handle empty authority section. (#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`.
Diffstat (limited to 'Lib/nturl2path.py')
-rw-r--r-- | Lib/nturl2path.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py index 9ecabff..255eb2f 100644 --- a/Lib/nturl2path.py +++ b/Lib/nturl2path.py @@ -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('/', '\\')) |