gh-122903: Honor directories in zipfile.Path.glob. (#122908)

This commit is contained in:
Jason R. Coombs 2024-08-11 20:33:33 -04:00 committed by GitHub
parent 9cd0326310
commit 6aa35f3002
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 9 deletions

View file

@ -28,7 +28,7 @@ class Translator:
"""
Given a glob pattern, produce a regex that matches it.
"""
return self.extend(self.translate_core(pattern))
return self.extend(self.match_dirs(self.translate_core(pattern)))
def extend(self, pattern):
r"""
@ -41,6 +41,14 @@ class Translator:
"""
return rf'(?s:{pattern})\Z'
def match_dirs(self, pattern):
"""
Ensure that zipfile.Path directory names are matched.
zipfile.Path directory names always end in a slash.
"""
return rf'{pattern}[/]?'
def translate_core(self, pattern):
r"""
Given a glob pattern, produce a regex that matches it.