diff options
Diffstat (limited to 'Lib/nturl2path.py')
-rw-r--r-- | Lib/nturl2path.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py index 01135d1b768..7e13ae31283 100644 --- a/Lib/nturl2path.py +++ b/Lib/nturl2path.py @@ -55,13 +55,17 @@ def pathname2url(p): p = p[4:] if p[:4].upper() == 'UNC/': p = '//' + p[4:] - drive, tail = ntpath.splitdrive(p) - if drive[1:] == ':': - # DOS drive specified. Add three slashes to the start, producing - # an authority section with a zero-length authority, and a path - # section starting with a single slash. - drive = f'///{drive}' + drive, root, tail = ntpath.splitroot(p) + if drive: + if drive[1:] == ':': + # DOS drive specified. Add three slashes to the start, producing + # an authority section with a zero-length authority, and a path + # section starting with a single slash. + drive = f'///{drive}' + drive = urllib.parse.quote(drive, safe='/:') + elif root: + # Add explicitly empty authority to path beginning with one slash. + root = f'//{root}' - drive = urllib.parse.quote(drive, safe='/:') tail = urllib.parse.quote(tail) - return drive + tail + return drive + root + tail |