Issue #23146: Fix mishandling of absolute Windows paths with forward … · python/cpython@57fffd6 · GitHub
Skip to content

Commit 57fffd6

Browse files
committed
Issue #23146: Fix mishandling of absolute Windows paths with forward slashes in pathlib.
Detected and fixed by Serhiy.
1 parent 0aa74e1 commit 57fffd6

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

Lib/pathlib.py

Lines changed: 4 additions & 0 deletions

Lib/test/test_pathlib.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,31 +105,35 @@ def test_parse_parts(self):
105105
check = self._check_parse_parts
106106
# First part is anchored
107107
check(['c:'], ('c:', '', ['c:']))
108-
check(['c:\\'], ('c:', '\\', ['c:\\']))
109-
check(['\\'], ('', '\\', ['\\']))
108+
check(['c:/'], ('c:', '\\', ['c:\\']))
109+
check(['/'], ('', '\\', ['\\']))
110110
check(['c:a'], ('c:', '', ['c:', 'a']))
111-
check(['c:\\a'], ('c:', '\\', ['c:\\', 'a']))
112-
check(['\\a'], ('', '\\', ['\\', 'a']))
111+
check(['c:/a'], ('c:', '\\', ['c:\\', 'a']))
112+
check(['/a'], ('', '\\', ['\\', 'a']))
113113
# UNC paths
114-
check(['\\\\a\\b'], ('\\\\a\\b', '\\', ['\\\\a\\b\\']))
115-
check(['\\\\a\\b\\'], ('\\\\a\\b', '\\', ['\\\\a\\b\\']))
116-
check(['\\\\a\\b\\c'], ('\\\\a\\b', '\\', ['\\\\a\\b\\', 'c']))
114+
check(['//a/b'], ('\\\\a\\b', '\\', ['\\\\a\\b\\']))
115+
check(['//a/b/'], ('\\\\a\\b', '\\', ['\\\\a\\b\\']))
116+
check(['//a/b/c'], ('\\\\a\\b', '\\', ['\\\\a\\b\\', 'c']))
117117
# Second part is anchored, so that the first part is ignored
118118
check(['a', 'Z:b', 'c'], ('Z:', '', ['Z:', 'b', 'c']))
119-
check(['a', 'Z:\\b', 'c'], ('Z:', '\\', ['Z:\\', 'b', 'c']))
120-
check(['a', '\\b', 'c'], ('', '\\', ['\\', 'b', 'c']))
119+
check(['a', 'Z:/b', 'c'], ('Z:', '\\', ['Z:\\', 'b', 'c']))
121120
# UNC paths
122-
check(['a', '\\\\b\\c', 'd'], ('\\\\b\\c', '\\', ['\\\\b\\c\\', 'd']))
121+
check(['a', '//b/c', 'd'], ('\\\\b\\c', '\\', ['\\\\b\\c\\', 'd']))
123122
# Collapsing and stripping excess slashes
124-
check(['a', 'Z:\\\\b\\\\c\\', 'd\\'], ('Z:', '\\', ['Z:\\', 'b', 'c', 'd']))
123+
check(['a', 'Z://b//c/', 'd/'], ('Z:', '\\', ['Z:\\', 'b', 'c', 'd']))
125124
# UNC paths
126-
check(['a', '\\\\b\\c\\\\', 'd'], ('\\\\b\\c', '\\', ['\\\\b\\c\\', 'd']))
125+
check(['a', '//b/c//', 'd'], ('\\\\b\\c', '\\', ['\\\\b\\c\\', 'd']))
127126
# Extended paths
128-
check(['\\\\?\\c:\\'], ('\\\\?\\c:', '\\', ['\\\\?\\c:\\']))
129-
check(['\\\\?\\c:\\a'], ('\\\\?\\c:', '\\', ['\\\\?\\c:\\', 'a']))
127+
check(['//?/c:/'], ('\\\\?\\c:', '\\', ['\\\\?\\c:\\']))
128+
check(['//?/c:/a'], ('\\\\?\\c:', '\\', ['\\\\?\\c:\\', 'a']))
129+
check(['//?/c:/a', '/b'], ('\\\\?\\c:', '\\', ['\\\\?\\c:\\', 'b']))
130130
# Extended UNC paths (format is "\\?\UNC\server\share")
131-
check(['\\\\?\\UNC\\b\\c'], ('\\\\?\\UNC\\b\\c', '\\', ['\\\\?\\UNC\\b\\c\\']))
132-
check(['\\\\?\\UNC\\b\\c\\d'], ('\\\\?\\UNC\\b\\c', '\\', ['\\\\?\\UNC\\b\\c\\', 'd']))
131+
check(['//?/UNC/b/c'], ('\\\\?\\UNC\\b\\c', '\\', ['\\\\?\\UNC\\b\\c\\']))
132+
check(['//?/UNC/b/c/d'], ('\\\\?\\UNC\\b\\c', '\\', ['\\\\?\\UNC\\b\\c\\', 'd']))
133+
# Second part has a root but not drive
134+
check(['a', '/b', 'c'], ('', '\\', ['\\', 'b', 'c']))
135+
check(['Z:/a', '/b', 'c'], ('Z:', '\\', ['Z:\\', 'b', 'c']))
136+
check(['//?/Z:/a', '/b', 'c'], ('\\\\?\\Z:', '\\', ['\\\\?\\Z:\\', 'b', 'c']))
133137

134138
def test_splitroot(self):
135139
f = self.flavour.splitroot

Misc/NEWS

Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)