diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-07-26 20:17:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-26 20:17:31 (GMT) |
commit | 4f6d7a5890760434015d9e90a6e81bf9e9b5c52f (patch) | |
tree | 337ef4553fa2da054d1b9b607023b9841ed0e6da /Lib/test | |
parent | 58af565c5085c427203ee424585a2c3ed0db4981 (diff) | |
download | cpython-4f6d7a5890760434015d9e90a6e81bf9e9b5c52f.zip cpython-4f6d7a5890760434015d9e90a6e81bf9e9b5c52f.tar.gz cpython-4f6d7a5890760434015d9e90a6e81bf9e9b5c52f.tar.bz2 |
[3.12] gh-105002: [pathlib] Fix relative_to with walk_up=True using ".." (GH-107014) (#107315)
gh-105002: [pathlib] Fix relative_to with walk_up=True using ".." (GH-107014)
It makes sense to raise an Error because ".." can not
be resolved and the current working directory is unknown.
(cherry picked from commit e7e6e4b035f51ab4a962b45a957254859f264f4f)
Co-authored-by: János Kukovecz <kukoveczjanos@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_pathlib.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 1d28a78..012dacf 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -626,8 +626,14 @@ class _BasePurePathTest(object): self.assertRaises(ValueError, p.relative_to, P('a/b/c')) self.assertRaises(ValueError, p.relative_to, P('a/c')) self.assertRaises(ValueError, p.relative_to, P('/a')) + self.assertRaises(ValueError, p.relative_to, P("../a")) + self.assertRaises(ValueError, p.relative_to, P("a/..")) + self.assertRaises(ValueError, p.relative_to, P("/a/..")) self.assertRaises(ValueError, p.relative_to, P('/'), walk_up=True) self.assertRaises(ValueError, p.relative_to, P('/a'), walk_up=True) + self.assertRaises(ValueError, p.relative_to, P("../a"), walk_up=True) + self.assertRaises(ValueError, p.relative_to, P("a/.."), walk_up=True) + self.assertRaises(ValueError, p.relative_to, P("/a/.."), walk_up=True) p = P('/a/b') self.assertEqual(p.relative_to(P('/')), P('a/b')) self.assertEqual(p.relative_to('/'), P('a/b')) @@ -656,8 +662,14 @@ class _BasePurePathTest(object): self.assertRaises(ValueError, p.relative_to, P()) self.assertRaises(ValueError, p.relative_to, '') self.assertRaises(ValueError, p.relative_to, P('a')) + self.assertRaises(ValueError, p.relative_to, P("../a")) + self.assertRaises(ValueError, p.relative_to, P("a/..")) + self.assertRaises(ValueError, p.relative_to, P("/a/..")) self.assertRaises(ValueError, p.relative_to, P(''), walk_up=True) self.assertRaises(ValueError, p.relative_to, P('a'), walk_up=True) + self.assertRaises(ValueError, p.relative_to, P("../a"), walk_up=True) + self.assertRaises(ValueError, p.relative_to, P("a/.."), walk_up=True) + self.assertRaises(ValueError, p.relative_to, P("/a/.."), walk_up=True) def test_is_relative_to_common(self): P = self.cls |