-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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-127236: pathname2url()
: generate RFC 1738 URL for absolute POSIX path
#127194
Conversation
… 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.
pathname2url()
: add authority section for absolute POSIX pathspathname2url()
: add authority for absolute POSIX paths
pathname2url()
: add authority for absolute POSIX pathspathname2url()
: add authority for absolute POSIX paths
pathname2url()
: add authority for absolute POSIX pathspathname2url()
: add authority for absolute POSIX paths
pathname2url()
: add authority for absolute POSIX pathspathname2url()
: RFC 1738 URL for absolute POSIX path
pathname2url()
: RFC 1738 URL for absolute POSIX pathpathname2url()
: generate RFC 1738 URL for absolute POSIX path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but could you somewhere make a difference between adding //
for path starting with /
and //
more explicit? It is necessary in the latter case, but cosmetic in the former case.
If RFC 8089 support will become more widespread and browsers and other programs will start normalizing the file:
URI to a single flash, this change can be reverted, but the case with double slash should still be handled specially.
Thanks v much Serhiy - I've adjusted the code comment to explain the difference between |
|
When handed an absolute Windows path such as
C:\foo
or\\server\share
, theurllib.request.pathname2url()
function returns a URL with an authority section, such as///C:/foo
or//server/share
(or before GH-126205,////server/share
). Only thefile:
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.See #127125 for a related clarification to the docs.
📚 Documentation preview 📚: https://cpython-previews--127194.org.readthedocs.build/
urllib.request.pathname2url()
: generate RFC 1738 URLs where possible #127236