GH-125866: pathname2url()
: add authority for absolute POSIX paths
#127194
+32
−17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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/
urllib.request
#125866