Skip to content

Commit

Permalink
pythongh-79382: Fix recursive glob() with trailing "**" (pythonGH-115134
Browse files Browse the repository at this point in the history
)

Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
  • Loading branch information
serhiy-storchaka authored and fsc-eriker committed Feb 14, 2024
1 parent 670c8c1 commit a88c67d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Lib/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def glob1(dirname, pattern):

def _glob2(dirname, pattern, dir_fd, dironly, include_hidden=False):
assert _isrecursive(pattern)
yield pattern[:0]
if not dirname or _isdir(dirname, dir_fd):
yield pattern[:0]
yield from _rlistdir(dirname, dir_fd, dironly,
include_hidden=include_hidden)

Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,17 @@ def test_recursive_glob(self):
eq(glob.glob('**', recursive=True, include_hidden=True),
[join(*i) for i in full+rec])

def test_glob_non_directory(self):
eq = self.assertSequencesEqual_noorder
eq(self.rglob('EF'), self.joins(('EF',)))
eq(self.rglob('EF', ''), [])
eq(self.rglob('EF', '*'), [])
eq(self.rglob('EF', '**'), [])
eq(self.rglob('nonexistent'), [])
eq(self.rglob('nonexistent', ''), [])
eq(self.rglob('nonexistent', '*'), [])
eq(self.rglob('nonexistent', '**'), [])

def test_glob_many_open_files(self):
depth = 30
base = os.path.join(self.tempdir, 'deep')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Trailing ``**`` no longer allows to match files and non-existing paths in
recursive :func:`~glob.glob`.

0 comments on commit a88c67d

Please sign in to comment.