cpython: 36864abbfe02 (original) (raw)
Mercurial > cpython
changeset 99780:36864abbfe02
Issue #26012: Don't traverse into symlinks for ** pattern in pathlib.Path.[r]glob(). (Merge 3.5->3.6) [#26012]
Guido van Rossum guido@dropbox.com | |
---|---|
date | Wed, 06 Jan 2016 10:36:19 -0800 |
parents | f6ae90450a4d(current diff)9826dbad1252(diff) |
children | d5f96a5da219 |
files | Lib/test/test_pathlib.py Misc/NEWS |
diffstat | 3 files changed, 22 insertions(+), 2 deletions(-)[+] [-] Lib/pathlib.py 2 Lib/test/test_pathlib.py 19 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -541,7 +541,7 @@ class _RecursiveWildcardSelector(_Select yield parent_path for name in listdir(parent_path): path = parent_path._make_child_relpath(name)
if is_dir(path):[](#l1.7)
if is_dir(path) and not path.is_symlink():[](#l1.8) for p in self._iterate_directories(path, is_dir, listdir):[](#l1.9) yield p[](#l1.10)
--- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1241,7 +1241,7 @@ class _BasePathTest(object): os.symlink('non-existing', join('brokenLink')) self.dirlink('dirB', join('linkB')) self.dirlink(os.path.join('..', 'dirB'), join('dirA', 'linkC'))
# This one goes upwards but doesn't create a loop[](#l2.7)
# This one goes upwards, creating a loop[](#l2.8) self.dirlink(os.path.join('..', 'dirB'), join('dirB', 'linkD'))[](#l2.9)
if os.name == 'nt': @@ -1437,6 +1437,23 @@ class _BasePathTest(object): _check(p.rglob("file*"), ["dirC/fileC", "dirC/dirD/fileD"]) _check(p.rglob("/"), ["dirC/dirD/fileD"])
- @with_symlinks
- def test_rglob_symlink_loop(self):
# Don't get fooled by symlink loops (Issue #26012)[](#l2.18)
P = self.cls[](#l2.19)
p = P(BASE)[](#l2.20)
given = set(p.rglob('*'))[](#l2.21)
expect = {'brokenLink',[](#l2.22)
'dirA', 'dirA/linkC',[](#l2.23)
'dirB', 'dirB/fileB', 'dirB/linkD',[](#l2.24)
'dirC', 'dirC/dirD', 'dirC/dirD/fileD', 'dirC/fileC',[](#l2.25)
'dirE',[](#l2.26)
'fileA',[](#l2.27)
'linkA',[](#l2.28)
'linkB',[](#l2.29)
}[](#l2.30)
self.assertEqual(given, {p / x for x in expect})[](#l2.31)
+ def test_glob_dotdot(self): # ".." is not special in globs P = self.cls
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -128,6 +128,9 @@ Core and Builtins Library ------- +- Issue #26012: Don't traverse into symlinks for ** pattern in