Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-85168: Use filesystem encoding when converting to/from file URIs #126852

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Nov 15, 2024

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.

…` URIs

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.
@barneygale
Copy link
Contributor Author

barneygale commented Nov 15, 2024

The freedesktop file URI spec is a useful reference here:

There is no specified encoding for filenames, and although we hope
that eventually all filenames will be encoded in UTF8 we can't rely on
this, because then we would be unable to e.g. rename a file with a
misencoded filename.

Also:

Some current apps generate file URIs by converting the filename from
whatever locale the application runs in to UTF8. This behavior means
that URIs can't be converted to filenames without knowing the
locale of the application that produced them, and that not all valid
filenames can be converted to URIs. Such behavior is not allowed,
and should be changed.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general. But we should support URIs containing not quoted non-ASCII characters.

Lib/urllib/request.py Outdated Show resolved Hide resolved
Lib/test/test_urllib.py Outdated Show resolved Hide resolved
@barneygale
Copy link
Contributor Author

Thanks for the review - I've made the changes you suggested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants