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-125866: pathname2url(): add authority for absolute POSIX paths #127194

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Nov 23, 2024

When handed an absolute Windows path such as C:\foo or \\server\share, the urllib.request.pathname2url() function returns a URL with an authority section, such as ///C:/foo or //server/share (or before GH-126205, ////server/share). Only the file: prefix is omitted.

But when handed an absolute POSIX path such as /etc/hosts, or a Windows path of the same form (rooted but lacking a drive), the function returns a URL without an authority section, such as /etc/hosts. This form of URL is acceptable, but it's very uncommon nowadays.

This patch corrects the discrepancy by adding a // prefix before drive-less, rooted paths when generating URLs.

See #127125 for a related clarification to the docs.


📚 Documentation preview 📚: https://cpython-previews--127194.org.readthedocs.build/

… POSIX paths

When handed an absolute Windows path such as `C:\foo` or `//server/share`,
the `urllib.request.pathname2url()` function returns a URL with an
authority section, such as `///C:/foo` or `//server/share` (or before
pythonGH-126205, `////server/share`). Only the `file:` prefix is omitted.

But when handed an absolute POSIX path such as `/etc/hosts`, or a Windows
path of the same form (rooted but lacking a drive), the function returns a
URL without an authority section, such as `/etc/hosts`.

This patch corrects the discrepancy by adding a `//` prefix before
drive-less, rooted paths when generating URLs.
@barneygale barneygale changed the title GH-126148: pathname2url(): add authority section for absolute POSIX paths GH-126148: pathname2url(): add authority for absolute POSIX paths Nov 23, 2024
@barneygale barneygale changed the title GH-126148: pathname2url(): add authority for absolute POSIX paths GH-125866: pathname2url(): add authority for absolute POSIX paths Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant