]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-127236: `pathname2url()`: generate RFC 1738 URL for absolute POSIX path (#127194)
authorBarney Gale <barney.gale@gmail.com>
Mon, 25 Nov 2024 19:59:20 +0000 (19:59 +0000)
committerGitHub <noreply@github.com>
Mon, 25 Nov 2024 19:59:20 +0000 (19:59 +0000)
commit5bb059fe606983814a445e4dcf9e96fd7cb4951a
tree676161387dee7f7b757b947199db07f8b29da54f
parenta2ee89968299fc4f0da4b5a4165025b941213ba5
GH-127236: `pathname2url()`: generate RFC 1738 URL for absolute POSIX path (#127194)

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 patch corrects the discrepancy by adding a `//` prefix before
drive-less, rooted paths when generating URLs.
Doc/library/urllib.request.rst
Lib/nturl2path.py
Lib/test/test_urllib.py
Lib/urllib/request.py
Misc/NEWS.d/next/Library/2024-11-23-12-25-06.gh-issue-125866.wEOP66.rst [new file with mode: 0644]