diff options
author | Barney Gale <barney.gale@gmail.com> | 2024-10-13 17:46:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-13 17:46:10 (GMT) |
commit | cb8e5995d89d9b90e83cf43310ec50e177484e70 (patch) | |
tree | 0a986d234ad90462a8a239431606a69511bc312b /Lib/test/test_pathlib/test_pathlib.py | |
parent | c6d7b644c2425b397cfb641f336bea70eb8a329a (diff) | |
download | cpython-cb8e5995d89d9b90e83cf43310ec50e177484e70.zip cpython-cb8e5995d89d9b90e83cf43310ec50e177484e70.tar.gz cpython-cb8e5995d89d9b90e83cf43310ec50e177484e70.tar.bz2 |
GH-125069: Fix inconsistent joining in `WindowsPath(PosixPath(...))` (#125156)
`PurePath.__init__()` incorrectly uses the `_raw_paths` of a given
`PurePath` object with a different flavour, even though the procedure to
join path segments can differ between flavours.
This change makes the `_raw_paths`-enabled deferred joining apply _only_
when the path flavours match.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_pathlib/test_pathlib.py')
-rw-r--r-- | Lib/test/test_pathlib/test_pathlib.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py index b47b4a1..c7104bf 100644 --- a/Lib/test/test_pathlib/test_pathlib.py +++ b/Lib/test/test_pathlib/test_pathlib.py @@ -131,6 +131,15 @@ class PurePathTest(test_pathlib_abc.DummyPurePathTest): self.assertEqual(P(P('a'), P('b'), P('c')), P(FakePath("a/b/c"))) self.assertEqual(P(P('./a:b')), P('./a:b')) + @needs_windows + def test_constructor_nested_foreign_flavour(self): + # See GH-125069. + p1 = pathlib.PurePosixPath('b/c:\\d') + p2 = pathlib.PurePosixPath('b/', 'c:\\d') + self.assertEqual(p1, p2) + self.assertEqual(self.cls(p1), self.cls('b/c:/d')) + self.assertEqual(self.cls(p2), self.cls('b/c:/d')) + def _check_parse_path(self, raw_path, *expected): sep = self.parser.sep actual = self.cls._parse_path(raw_path.replace('/', sep)) |