summaryrefslogtreecommitdiffstats
path: root/Lib/urllib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-11-24 17:30:29 (GMT)
committerGitHub <noreply@github.com>2024-11-24 17:30:29 (GMT)
commit97b2ceaaaf88a73a45254912a0e972412879ccbf (patch)
tree0d103bb0bf447a581c49142da72c8293f87394fb /Lib/urllib
parent2bb7846cacb342246aada5ed92d323e54c946063 (diff)
downloadcpython-97b2ceaaaf88a73a45254912a0e972412879ccbf.zip
cpython-97b2ceaaaf88a73a45254912a0e972412879ccbf.tar.gz
cpython-97b2ceaaaf88a73a45254912a0e972412879ccbf.tar.bz2
gh-127217: Fix pathname2url() for paths starting with multiple slashes on Posix (GH-127218)
Diffstat (limited to 'Lib/urllib')
-rw-r--r--Lib/urllib/request.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 80be65c..9e55543 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1667,6 +1667,10 @@ else:
def pathname2url(pathname):
"""OS-specific conversion from a file system path to a relative URL
of the 'file' scheme; not recommended for general use."""
+ if pathname[:2] == '//':
+ # Add explicitly empty authority to avoid interpreting the path
+ # as authority.
+ pathname = '//' + pathname
encoding = sys.getfilesystemencoding()
errors = sys.getfilesystemencodeerrors()
return quote(pathname, encoding=encoding, errors=errors)