diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-11-19 21:19:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 21:19:30 (GMT) |
commit | c9b399fbdb01584dcfff0d7f6ad484644ff269c3 (patch) | |
tree | 4e7fe4fa8d106d35597ec8c2f969e7e58ba9517c /Lib/urllib | |
parent | 2cdfb41d0c3bfea37983fc872951bc3b2a4d90b8 (diff) | |
download | cpython-c9b399fbdb01584dcfff0d7f6ad484644ff269c3.zip cpython-c9b399fbdb01584dcfff0d7f6ad484644ff269c3.tar.gz cpython-c9b399fbdb01584dcfff0d7f6ad484644ff269c3.tar.bz2 |
GH-85168: Use filesystem encoding when converting to/from `file` URIs (#126852)
Adjust `urllib.request.url2pathname()` and `pathname2url()` to use the
filesystem encoding when quoting and unquoting file URIs, rather than
forcing use of UTF-8.
No changes are needed in the `nturl2path` module because Windows always
uses UTF-8, per PEP 529.
Diffstat (limited to 'Lib/urllib')
-rw-r--r-- | Lib/urllib/request.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 5c061a2..bcfdcc5 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1657,12 +1657,16 @@ else: # URL has an empty authority section, so the path begins on the # third character. pathname = pathname[2:] - return unquote(pathname) + encoding = sys.getfilesystemencoding() + errors = sys.getfilesystemencodeerrors() + return unquote(pathname, encoding=encoding, errors=errors) def pathname2url(pathname): """OS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use.""" - return quote(pathname) + encoding = sys.getfilesystemencoding() + errors = sys.getfilesystemencodeerrors() + return quote(pathname, encoding=encoding, errors=errors) # Utility functions |