summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-11-23 10:41:39 (GMT)
committerGitHub <noreply@github.com>2024-11-23 10:41:39 (GMT)
commitcc813e10ff190af38b8429d0d49fb9249493d504 (patch)
tree249d31c6fda7061ff11524c551511a11112992c3 /Lib
parenta13e94d84bff334da3da2cab523ba75b57e0787f (diff)
downloadcpython-cc813e10ff190af38b8429d0d49fb9249493d504.zip
cpython-cc813e10ff190af38b8429d0d49fb9249493d504.tar.gz
cpython-cc813e10ff190af38b8429d0d49fb9249493d504.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/nturl2path.py4
-rw-r--r--Lib/test/test_urllib.py2
2 files changed, 4 insertions, 2 deletions
diff --git a/Lib/nturl2path.py b/Lib/nturl2path.py
index 66092e4..01135d1 100644
--- a/Lib/nturl2path.py
+++ b/Lib/nturl2path.py
@@ -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)
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index a204ef4..22ef3c6 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -1423,6 +1423,7 @@ class Pathname_Tests(unittest.TestCase):
self.assertEqual(fn('\\\\?\\unc\\server\\share\\dir'), '//server/share/dir')
self.assertEqual(fn("C:"), '///C:')
self.assertEqual(fn("C:\\"), '///C:/')
+ self.assertEqual(fn('c:\\a\\b.c'), '///c:/a/b.c')
self.assertEqual(fn('C:\\a\\b.c'), '///C:/a/b.c')
self.assertEqual(fn('C:\\a\\b.c\\'), '///C:/a/b.c/')
self.assertEqual(fn('C:\\a\\\\b.c'), '///C:/a//b.c')
@@ -1480,6 +1481,7 @@ class Pathname_Tests(unittest.TestCase):
self.assertEqual(fn("///C/test/"), '\\C\\test\\')
self.assertEqual(fn("////C/test/"), '\\\\C\\test\\')
# DOS drive paths
+ self.assertEqual(fn('c:/path/to/file'), 'c:\\path\\to\\file')
self.assertEqual(fn('C:/path/to/file'), 'C:\\path\\to\\file')
self.assertEqual(fn('C:/path/to/file/'), 'C:\\path\\to\\file\\')
self.assertEqual(fn('C:/path/to//file'), 'C:\\path\\to\\\\file')