GH-89769: pathlib.Path.glob(): do not follow symlinks when checking for precise match (GH-29655)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
This commit is contained in:
andrei kulakov 2023-05-02 23:50:10 -04:00 committed by GitHub
parent c7c3a60c88
commit af886ffa06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 9 deletions

View file

@ -1700,6 +1700,8 @@ class _BasePathTest(object):
self.assertIs(True, (p / 'linkB').exists())
self.assertIs(True, (p / 'linkB' / 'fileB').exists())
self.assertIs(False, (p / 'linkA' / 'bah').exists())
self.assertIs(False, (p / 'brokenLink').exists())
self.assertIs(True, (p / 'brokenLink').exists(follow_symlinks=False))
self.assertIs(False, (p / 'foo').exists())
self.assertIs(False, P('/xyzzy').exists())
self.assertIs(False, P(BASE + '\udfff').exists())
@ -1806,6 +1808,8 @@ class _BasePathTest(object):
_check(p.glob("*/fileB"), ['dirB/fileB'])
else:
_check(p.glob("*/fileB"), ['dirB/fileB', 'linkB/fileB'])
if os_helper.can_symlink():
_check(p.glob("brokenLink"), ['brokenLink'])
if not os_helper.can_symlink():
_check(p.glob("*/"), ["dirA", "dirB", "dirC", "dirE"])