gh-127217: Fix pathname2url() for paths starting with multiple slashes on Posix (GH-127218)

This commit is contained in:
Serhiy Storchaka 2024-11-24 19:30:29 +02:00 committed by GitHub
parent 2bb7846cac
commit 97b2ceaaaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 0 deletions

View file

@ -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)