Skip to content

Commit

Permalink
Backport handling of * segments from main.
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Jul 3, 2023
1 parent e320740 commit 799044d
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit 799044d

Please sign in to comment.