mirror of
https://github.com/python/cpython.git
synced 2025-07-28 21:55:21 +00:00
[3.13] GH-126212: Fix removal of slashes in file URIs on Windows (GH-126214) (#126590)
GH-126212: Fix removal of slashes in file URIs on Windows (GH-126214)
Adjust `urllib.request.pathname2url()` and `url2pathname()` so that they
don't remove slashes from Windows DOS drive paths and URLs. There was no
basis for this behaviour, and it conflicts with how UNC and POSIX paths are
handled.
(cherry picked from commit 54c63a32d0
)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
parent
b1a406d923
commit
20043d5cf4
3 changed files with 18 additions and 21 deletions
|
@ -1526,8 +1526,10 @@ class Pathname_Tests(unittest.TestCase):
|
|||
self.assertEqual(fn('\\\\?\\C:\\dir'), '///C:/dir')
|
||||
self.assertEqual(fn('\\\\?\\unc\\server\\share\\dir'), '//server/share/dir')
|
||||
self.assertEqual(fn("C:"), '///C:')
|
||||
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%25%23c')
|
||||
self.assertEqual(fn('C:\\a\\b\xe9'), '///C:/a/b%C3%A9')
|
||||
self.assertEqual(fn('C:\\foo\\bar\\spam.foo'), "///C:/foo/bar/spam.foo")
|
||||
|
@ -1563,13 +1565,15 @@ class Pathname_Tests(unittest.TestCase):
|
|||
self.assertEqual(fn("///C|"), 'C:')
|
||||
self.assertEqual(fn("///C:"), 'C:')
|
||||
self.assertEqual(fn('///C:/'), 'C:\\')
|
||||
self.assertEqual(fn('/C|//'), 'C:\\')
|
||||
self.assertEqual(fn('/C|//'), 'C:\\\\')
|
||||
self.assertEqual(fn('///C|/path'), 'C:\\path')
|
||||
# No DOS drive
|
||||
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')
|
||||
self.assertEqual(fn('/C|/path/to/file'), 'C:\\path\\to\\file')
|
||||
self.assertEqual(fn('///C|/path/to/file'), 'C:\\path\\to\\file')
|
||||
|
@ -1583,6 +1587,9 @@ class Pathname_Tests(unittest.TestCase):
|
|||
# Localhost paths
|
||||
self.assertEqual(fn('//localhost/C:/path/to/file'), 'C:\\path\\to\\file')
|
||||
self.assertEqual(fn('//localhost/C|/path/to/file'), 'C:\\path\\to\\file')
|
||||
# Percent-encoded forward slashes are preserved for backwards compatibility
|
||||
self.assertEqual(fn('C:/foo%2fbar'), 'C:\\foo/bar')
|
||||
self.assertEqual(fn('//server/share/foo%2fbar'), '\\\\server\\share\\foo/bar')
|
||||
# Round-tripping
|
||||
paths = ['C:',
|
||||
r'\\\C\test\\',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue