-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-36305: Fixes to path handling and parsing in pathlib #12361
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,7 +114,6 @@ def test_parse_parts(self): | |
check(['//a/b/'], ('\\\\a\\b', '\\', ['\\\\a\\b\\'])) | ||
check(['//a/b/c'], ('\\\\a\\b', '\\', ['\\\\a\\b\\', 'c'])) | ||
# Second part is anchored, so that the first part is ignored. | ||
check(['a', 'Z:b', 'c'], ('Z:', '', ['Z:', 'b', 'c'])) | ||
check(['a', 'Z:/b', 'c'], ('Z:', '\\', ['Z:\\', 'b', 'c'])) | ||
# UNC paths. | ||
check(['a', '//b/c', 'd'], ('\\\\b\\c', '\\', ['\\\\b\\c\\', 'd'])) | ||
|
@@ -133,6 +132,16 @@ def test_parse_parts(self): | |
check(['a', '/b', 'c'], ('', '\\', ['\\', 'b', 'c'])) | ||
check(['Z:/a', '/b', 'c'], ('Z:', '\\', ['Z:\\', 'b', 'c'])) | ||
check(['//?/Z:/a', '/b', 'c'], ('\\\\?\\Z:', '\\', ['\\\\?\\Z:\\', 'b', 'c'])) | ||
# Second part has a drive but not root. | ||
check(['a', 'Z:b', 'c'], ('Z:', '', ['Z:', 'a', 'b', 'c'])) | ||
check(['Y:a', 'Z:b', 'c'], ('Z:', '', ['Z:', 'a', 'b', 'c'])) | ||
# Paths to files with NTFS alternate data streams | ||
check(['./c:s'], ('', '', ['c:s'])) | ||
check(['cc:s'], ('', '', ['cc:s'])) | ||
check(['C:c:s'], ('C:', '', ['C:', 'c:s'])) | ||
check(['C:/c:s'], ('C:', '\\', ['C:\\', 'c:s'])) | ||
check(['D:a', './c:b'], ('D:', '', ['D:', 'a', 'c:b'])) | ||
check(['D:/a', './c:b'], ('D:', '\\', ['D:\\', 'a', 'c:b'])) | ||
|
||
def test_splitroot(self): | ||
f = self.flavour.splitroot | ||
|
@@ -201,6 +210,7 @@ def test_constructor_common(self): | |
self.assertEqual(P(P('a'), 'b'), P('a/b')) | ||
self.assertEqual(P(P('a'), P('b')), P('a/b')) | ||
self.assertEqual(P(P('a'), P('b'), P('c')), P(FakePath("a/b/c"))) | ||
self.assertEqual(P(P('./a:b')), P('./a:b')) | ||
|
||
def _check_str_subclass(self, *args): | ||
# Issue #21127: it should be possible to construct a PurePath object | ||
|
@@ -746,7 +756,9 @@ class PureWindowsPathTest(_BasePurePathTest, unittest.TestCase): | |
|
||
equivalences = _BasePurePathTest.equivalences.copy() | ||
equivalences.update({ | ||
'c:a': [ ('c:', 'a'), ('c:', 'a/'), ('/', 'c:', 'a') ], | ||
'./a:b': [ ('./a:b',) ], | ||
'a:b:c': [ ('./b:c', 'a:'), ('b:', 'a:b:c') ], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the above, I don't see why |
||
'c:a': [ ('c:', 'a'), ('c:', 'a/'), ('.', 'c:', 'a') ], | ||
'c:/a': [ | ||
('c:/', 'a'), ('c:', '/', 'a'), ('c:', '/a'), | ||
('/z', 'c:/', 'a'), ('//x/y', 'c:/', 'a'), | ||
|
@@ -770,6 +782,7 @@ def test_str(self): | |
self.assertEqual(str(p), '\\\\a\\b\\c\\d') | ||
|
||
def test_str_subclass(self): | ||
self._check_str_subclass('.\\a:b') | ||
self._check_str_subclass('c:') | ||
self._check_str_subclass('c:a') | ||
self._check_str_subclass('c:a\\b.txt') | ||
|
@@ -916,6 +929,7 @@ def test_drive(self): | |
self.assertEqual(P('//a/b').drive, '\\\\a\\b') | ||
self.assertEqual(P('//a/b/').drive, '\\\\a\\b') | ||
self.assertEqual(P('//a/b/c/d').drive, '\\\\a\\b') | ||
self.assertEqual(P('./c:a').drive, '') | ||
|
||
def test_root(self): | ||
P = self.cls | ||
|
@@ -1191,6 +1205,14 @@ def test_join(self): | |
self.assertEqual(pp, P('C:/a/b/x/y')) | ||
pp = p.joinpath('c:/x/y') | ||
self.assertEqual(pp, P('C:/x/y')) | ||
# Joining with files with NTFS data streams => the filename should | ||
# not be parsed as a drive letter | ||
pp = p.joinpath(P('./d:s')) | ||
self.assertEqual(pp, P('C:/a/b/d:s')) | ||
pp = p.joinpath(P('./dd:s')) | ||
self.assertEqual(pp, P('C:/a/b/dd:s')) | ||
pp = p.joinpath(P('E:d:s')) | ||
self.assertEqual(pp, P('E:d:s')) | ||
|
||
def test_div(self): | ||
# Basically the same as joinpath(). | ||
|
@@ -1211,6 +1233,11 @@ def test_div(self): | |
# the second path is relative. | ||
self.assertEqual(p / 'c:x/y', P('C:/a/b/x/y')) | ||
self.assertEqual(p / 'c:/x/y', P('C:/x/y')) | ||
# Joining with files with NTFS data streams => the filename should | ||
# not be parsed as a drive letter | ||
self.assertEqual(p / P('./d:s'), P('C:/a/b/d:s')) | ||
self.assertEqual(p / P('./dd:s'), P('C:/a/b/dd:s')) | ||
self.assertEqual(p / P('E:d:s'), P('E:d:s')) | ||
|
||
def test_is_reserved(self): | ||
P = self.cls | ||
|
@@ -1431,6 +1458,8 @@ def test_expanduser_common(self): | |
self.assertEqual(p.expanduser(), p) | ||
p = P(P('').absolute().anchor) / '~' | ||
self.assertEqual(p.expanduser(), p) | ||
p = P('~/a:b') | ||
self.assertEqual(p.expanduser(), P(os.path.expanduser('~'), './a:b')) | ||
|
||
def test_exists(self): | ||
P = self.cls | ||
|
@@ -2467,11 +2496,16 @@ def check(): | |
env.pop('HOMEPATH', None) | ||
env['USERPROFILE'] = 'C:\\Users\\alice' | ||
check() | ||
|
||
# bpo-38883: ignore `HOME` when set on windows | ||
env['HOME'] = 'C:\\Users\\eve' | ||
check() | ||
|
||
def test_resolve(self): | ||
P = self.cls | ||
p = P(BASE, './a:b') | ||
self.assertEqual(str(p.resolve(strict=False)), f'{BASE}\\a:b') | ||
|
||
|
||
class CompatiblePathTest(unittest.TestCase): | ||
""" | ||
|
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2019-03-15-22-50-27.bpo-36305.Pbkv6u.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a ``pathlib`` inconsistency in handling of paths containing colons. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right - if we switch drives mid-way through we should discard everything before. This is what
os.path.join()
does.