mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
[3.11] gh-79382: Fix recursive glob() with trailing "**" (GH-115134) (GH-115291)
Trailing "**" no longer allows to match files and non-existing paths in
recursive glob().
(cherry picked from commit aeffc7f895
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
446a6db5e1
commit
e72255054b
3 changed files with 15 additions and 1 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -332,6 +332,17 @@ class GlobTests(unittest.TestCase):
|
|||
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')
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Trailing ``**`` no longer allows to match files and non-existing paths in
|
||||
recursive :func:`~glob.glob`.
|
Loading…
Add table
Add a link
Reference in a new issue