diff options
| author | Barney Gale <barney.gale@gmail.com> | 2023-09-26 16:57:17 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-26 16:57:17 (GMT) |
| commit | ecd813f054e0dee890d484b8210e202175abd632 (patch) | |
| tree | d3f337b83ab0936b04c00f34f2f3a30e96d78405 /Lib/test/test_pathlib.py | |
| parent | 859618c8cd5de86a975e68d7e5d20c04bc5db2e5 (diff) | |
| download | cpython-ecd813f054e0dee890d484b8210e202175abd632.zip cpython-ecd813f054e0dee890d484b8210e202175abd632.tar.gz cpython-ecd813f054e0dee890d484b8210e202175abd632.tar.bz2 | |
GH-109187: Improve symlink loop handling in `pathlib.Path.resolve()` (GH-109192)
Treat symlink loops like other errors: in strict mode, raise `OSError`, and
in non-strict mode, do not raise any exception.
Diffstat (limited to 'Lib/test/test_pathlib.py')
| -rw-r--r-- | Lib/test/test_pathlib.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 09df3fe..484a5e6 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -3178,10 +3178,11 @@ class PosixPathTest(PathTest): self.assertEqual(str(P('//a').absolute()), '//a') self.assertEqual(str(P('//a/b').absolute()), '//a/b') - def _check_symlink_loop(self, *args, strict=True): + def _check_symlink_loop(self, *args): path = self.cls(*args) - with self.assertRaises(RuntimeError): - print(path.resolve(strict)) + with self.assertRaises(OSError) as cm: + path.resolve(strict=True) + self.assertEqual(cm.exception.errno, errno.ELOOP) @unittest.skipIf( is_emscripten or is_wasi, @@ -3240,7 +3241,8 @@ class PosixPathTest(PathTest): os.symlink('linkZ/../linkZ', join('linkZ')) self._check_symlink_loop(BASE, 'linkZ') # Non-strict - self._check_symlink_loop(BASE, 'linkZ', 'foo', strict=False) + p = self.cls(BASE, 'linkZ', 'foo') + self.assertEqual(p.resolve(strict=False), p) # Loops with absolute symlinks. os.symlink(join('linkU/inside'), join('linkU')) self._check_symlink_loop(BASE, 'linkU') @@ -3249,7 +3251,8 @@ class PosixPathTest(PathTest): os.symlink(join('linkW/../linkW'), join('linkW')) self._check_symlink_loop(BASE, 'linkW') # Non-strict - self._check_symlink_loop(BASE, 'linkW', 'foo', strict=False) + q = self.cls(BASE, 'linkW', 'foo') + self.assertEqual(q.resolve(strict=False), q) def test_glob(self): P = self.cls |
