Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Backport handling of * segments from main.
  • Loading branch information
barneygale committed Jul 3, 2023
commit 799044d3047c3c0ea7a6ed41e249a26c6a1fafa9
19 changes: 13 additions & 6 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,19 @@ def _compile_pattern_lines(pattern_lines, case_sensitive):
# Match the start of the path, or just after a path separator
parts = ['^']
for part in pattern_lines.splitlines(keepends=True):
# We slice off the common prefix and suffix added by translate() to
# ensure that re.DOTALL is not set, and the end of the string not
# matched, respectively. With DOTALL not set, '*' wildcards will not
# match path separators, because the '.' characters in the pattern
# will not match newlines.
parts.append(fnmatch.translate(part)[_FNMATCH_SLICE])
if part == '*\n':
part = r'.+\n'
elif part == '*':
part = r'.+'
else:
# Any other component: pass to fnmatch.translate(). We slice off
# the common prefix and suffix added by translate() to ensure that
# re.DOTALL is not set, and the end of the string not matched,
# respectively. With DOTALL not set, '*' wildcards will not match
# path separators, because the '.' characters in the pattern will
# not match newlines.
part = fnmatch.translate(part)[_FNMATCH_SLICE]
parts.append(part)
# Match the end of the path, always.
parts.append(r'\Z')
flags = re.MULTILINE
Expand Down