8000 GH-109187: Improve symlink loop handling in `pathlib.Path.resolve()` by barneygale · Pull Request #109192 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-109187: Improve symlink loop handling in pathlib.Path.resolve() #109192

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve tests
  • Loading branch information
barneygale committed Sep 9, 2023
commit 9bc2743e4f5a19dbe4bb2c241b09a1270d8173dc
17 changes: 8 additions & 9 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3178,14 +3178,11 @@ def test_absolute(self):
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)
if strict:
with self.assertRaises(OSError) as cm:
path.resolve(strict=True)
self.assertEqual(cm.exception.errno, errno.ELOOP)
else:
path.resolve(strict=False)
with self.assertRaises(OSError) as cm:
path.resolve(strict=True)
self.assertEqual(cm.exception.errno, errno.ELOOP)

@unittest.skipIf(
is_emscripten or is_wasi,
Expand Down Expand Up @@ -3244,7 +3241,8 @@ def test_resolve_loop(self):
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')
Expand All @@ -3253,7 +3251,8 @@ def test_resolve_loop(self):
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
Expand Down
0