GH-125866: Preserve Windows drive letter case in file URIs (#127138)

Stop converting Windows drive letters to uppercase in
`urllib.request.pathname2url()` and `url2pathname()`. This behaviour is
unnecessary and inconsistent with pathlib's file URI implementation.
This commit is contained in:
Barney Gale 2024-11-23 10:41:39 +00:00 committed by GitHub
parent a13e94d84b
commit cc813e10ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 2 deletions

View file

@ -35,7 +35,7 @@ def url2pathname(url):
if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
error = 'Bad URL: ' + url
raise OSError(error)
drive = comp[0][-1].upper()
drive = comp[0][-1]
tail = urllib.parse.unquote(comp[1].replace('/', '\\'))
return drive + ':' + tail
@ -60,7 +60,7 @@ def pathname2url(p):
# 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.upper()}'
drive = f'///{drive}'
drive = urllib.parse.quote(drive, safe='/:')
tail = urllib.parse.quote(tail)