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/urllib/request.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/urllib/request.py')
-rw-r--r-- | Lib/urllib/request.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index bcfdcc5..80be65c 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1657,6 +1657,9 @@ else: # URL has an empty authority section, so the path begins on the # third character. pathname = pathname[2:] + elif pathname[:12] == '//localhost/': + # Skip past 'localhost' authority. + pathname = pathname[11:] encoding = sys.getfilesystemencoding() errors = sys.getfilesystemencodeerrors() return unquote(pathname, encoding=encoding, errors=errors) |