[3.13] GH-126205: Fix conversion of UNC paths to file URIs (GH-126208) (#126249)

GH-126205: Fix conversion of UNC paths to file URIs (GH-126208)

File URIs for Windows UNC paths should begin with two slashes, not four.
(cherry picked from commit 951cb2c369)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-10-31 17:58:56 +01:00 committed by GitHub
parent 80042384b4
commit 588da2e26a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 13 deletions

View file

@ -55,16 +55,11 @@ def pathname2url(p):
if p[:4] == '\\\\?\\':
p = p[4:]
if p[:4].upper() == 'UNC\\':
p = '\\' + p[4:]
p = '\\\\' + p[4:]
elif p[1:2] != ':':
raise OSError('Bad path: ' + p)
if not ':' in p:
# No drive specifier, just convert slashes and quote the name
if p[:2] == '\\\\':
# path is something like \\host\path\on\remote\host
# convert this to ////host/path/on/remote/host
# (notice doubling of slashes at the start of the path)
p = '\\\\' + p
components = p.split('\\')
return urllib.parse.quote('/'.join(components))
comp = p.split(':', maxsplit=2)