GH-85168: Use filesystem encoding when converting to/from file URIs by barneygale · Pull Request #126852 · python/cpython (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation9 Commits5 Checks38 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

barneygale

Contributor

@barneygale barneygale commented

Nov 15, 2024

edited by bedevere-appbot

Loading

@barneygale

…` 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

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.

serhiy-storchaka

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.

@barneygale

@barneygale

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

@barneygale

@barneygale

serhiy-storchaka

Choose a reason for hiding this comment

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

LGTM.

You can also use fsdecode(TESTFN_UNDECODABLE) and TESTFN_UNENCODABLE in some tests if you wish.

ruidazeng

@barneygale

@miss-islington-app

Thanks @barneygale for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Nov 19, 2024

@barneygale @miss-islington

…` URIs (pythonGH-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. (cherry picked from commit c9b399f)

Co-authored-by: Barney Gale barney.gale@gmail.com

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Nov 19, 2024

@barneygale @miss-islington

…` URIs (pythonGH-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. (cherry picked from commit c9b399f)

Co-authored-by: Barney Gale barney.gale@gmail.com

@bedevere-app

@bedevere-app

barneygale added a commit that referenced this pull request

Nov 19, 2024

@miss-islington @barneygale

…e` URIs (GH-126852) (#127040)

GH-85168: Use filesystem encoding when converting to/from file URIs (GH-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. (cherry picked from commit c9b399f)

Co-authored-by: Barney Gale barney.gale@gmail.com

barneygale added a commit that referenced this pull request

Nov 20, 2024

@miss-islington @barneygale

…e` URIs (GH-126852) (#127039)

GH-85168: Use filesystem encoding when converting to/from file URIs (GH-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. (cherry picked from commit c9b399f)

Co-authored-by: Barney Gale barney.gale@gmail.com

ebonnal pushed a commit to ebonnal/cpython that referenced this pull request

Jan 12, 2025

@barneygale @ebonnal

…` URIs (python#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.