Skip to content

Commit

Permalink
Fix possible scoping issue in _glob()
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 7, 2023
1 parent b852339 commit 2b77a61
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ def _compile_pattern(pat, sep, case_sensitive):
return re.compile(regex, flags=flags).match


def _select_parents(paths, dir_only):
"""Yield lexical parents of the given paths."""
for path in paths:
yield path._make_child_relpath('..', dir_only)


def _select_children(parent_paths, dir_only, follow_symlinks, match):
"""Yield direct children of given paths, filtering by name and type."""
if follow_symlinks is None:
Expand Down Expand Up @@ -1105,7 +1111,7 @@ def _glob(self, pattern, case_sensitive, follow_symlinks):
pass
elif part == '..':
dir_only = part_idx < len(pattern_parts)
paths = (path._make_child_relpath('..', dir_only) for path in paths)
paths = _select_parents(paths, dir_only)
elif part == '**':
# Consume adjacent '**' components.
while part_idx < len(pattern_parts) and pattern_parts[part_idx] == '**':
Expand Down

0 comments on commit 2b77a61

Please sign in to comment.