diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-11-22 03:17:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-22 03:17:06 (GMT) |
commit | ebf564a1d3e2e81b9846535114e481d6096443d2 (patch) | |
tree | 62a0618bdaca77bde5822e9c0902851872174cb9 /Lib/nturl2path.py | |
parent | fcfdb55465636afc256bc29781b283404d88e6ca (diff) | |
download | cpython-ebf564a1d3e2e81b9846535114e481d6096443d2.zip cpython-ebf564a1d3e2e81b9846535114e481d6096443d2.tar.gz cpython-ebf564a1d3e2e81b9846535114e481d6096443d2.tar.bz2 |
GH-126766: `url2pathname()`: handle 'localhost' authority (#127129)
Discard any 'localhost' authority from the beginning of a `file:` URI. As a
result, file URIs like `//localhost/etc/hosts` are correctly decoded as
`/etc/hosts`.
Diffstat (limited to 'Lib/nturl2path.py')
-rw-r--r-- | Lib/nturl2path.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py index ed7880f..3308ee7 100644 --- a/Lib/nturl2path.py +++ b/Lib/nturl2path.py @@ -15,14 +15,17 @@ def url2pathname(url): # become # C:\foo\bar\spam.foo import string, urllib.parse + if url[:3] == '///': + # URL has an empty authority section, so the path begins on the third + # character. + url = url[2:] + elif url[:12] == '//localhost/': + # Skip past 'localhost' authority. + url = url[11:] # Windows itself uses ":" even in URLs. url = url.replace(':', '|') if not '|' in url: # No drive specifier, just convert slashes - 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('/', '\\')) comp = url.split('|') |