Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Doc/library/urllib.request.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ The :mod:`urllib.request` module defines the following functions:
the path component of a URL. This does not produce a complete URL. The return
value will already be quoted using the :func:`~urllib.parse.quote` function.

.. versionchanged:: 3.14
Windows drive letters are no longer converted to uppercase.

.. versionchanged:: 3.14
On Windows, ``:`` characters not following a drive letter are quoted. In
previous versions, :exc:`OSError` was raised if a colon character was
Expand All @@ -164,6 +167,10 @@ The :mod:`urllib.request` module defines the following functions:
path. This does not accept a complete URL. This function uses
:func:`~urllib.parse.unquote` to decode *path*.

.. versionchanged:: 3.14
Windows drive letters are no longer converted to uppercase.


.. function:: getproxies()

This helper function returns a dictionary of scheme to proxy server URL
Expand Down
4 changes: 2 additions & 2 deletions Lib/nturl2path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ def test_pathname2url_win(self):
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')
Expand Down Expand Up @@ -1480,6 +1481,7 @@ def test_url2pathname_win(self):
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')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`urllib.request.pathname2url` and :func:`~urllib.request.url2pathname`
no longer convert Windows drive letters to uppercase.
Loading