Skip to content

Commit

Permalink
Ignore trailing slash when matching terminal ** sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Feb 8, 2025
1 parent 266c995 commit 3d3a82a
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions Lib/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,6 @@ def recursive_selector(self, part, parts):
if follow_symlinks:
while parts and parts[-1] not in _special_parts:
part += self.sep + parts.pop()
if parts:
part += self.sep

match = None if part == '**' else self.compile(part)
dir_only = bool(parts)
select_next = self.selector(parts)
Expand Down Expand Up @@ -489,20 +486,19 @@ def select_recursive_step(stack, match_pos):
except OSError:
pass

if dir_only:
if not is_dir:
continue
entry_path = self.concat_path(entry_path, self.sep)

if match is None or match(str(entry_path), match_pos):
if is_dir or not dir_only:
entry_path_str = str(entry_path)
if dir_only:
yield from select_next(entry_path, exists=True)
else:
# Optimization: directly yield the path if this is
# last pattern part.
yield entry_path
if is_dir:
stack.append(entry_path)
entry_path = self.concat_path(entry_path, self.sep)
if match is None or match(entry_path_str, match_pos):
if dir_only:
yield from select_next(entry_path, exists=True)
else:
# Optimization: directly yield the path if this is
# last pattern part.
yield entry_path
if is_dir:
stack.append(entry_path)

return select_recursive

Expand Down

0 comments on commit 3d3a82a

Please sign in to comment.