-
-
Couldn't load subscription status.
- Fork 33.3k
gh-130942: Fix path seperator matched in character ranges for glob.translate #130989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
be37b54
b874745
6990566
cc03a6d
cea1f5e
5251d75
dd1b155
e8b3559
9f461a5
4820018
c7f6d87
d5748b8
95b4ccf
cdfcf47
3929b06
e5abc80
93c3092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -87,6 +87,7 @@ def _translate(pat, star, question_mark): | |||||
| res = [] | ||||||
| add = res.append | ||||||
| star_indices = [] | ||||||
| inside_range=False | ||||||
|
|
||||||
| i, n = 0, len(pat) | ||||||
| while i < n: | ||||||
|
|
@@ -135,18 +136,31 @@ def _translate(pat, star, question_mark): | |||||
| if chunks[k-1][-1] > chunks[k][0]: | ||||||
| chunks[k-1] = chunks[k-1][:-1] + chunks[k][1:] | ||||||
| del chunks[k] | ||||||
|
|
||||||
| if len(chunks)>1: | ||||||
|
||||||
| if len(chunks)>1: | |
| if len(chunks) > 1: |
picnixz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
picnixz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
picnixz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,7 +263,6 @@ def escape(pathname): | |
| _dir_open_flags = os.O_RDONLY | getattr(os, 'O_DIRECTORY', 0) | ||
| _no_recurse_symlinks = object() | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert. |
||
| def translate(pat, *, recursive=False, include_hidden=False, seps=None): | ||
| """Translate a pathname with shell wildcards to a regular expression. | ||
|
|
||
|
|
@@ -282,6 +281,8 @@ def translate(pat, *, recursive=False, include_hidden=False, seps=None): | |
| seps = (os.path.sep, os.path.altsep) | ||
| else: | ||
| seps = os.path.sep | ||
|
|
||
|
|
||
| escaped_seps = ''.join(map(re.escape, seps)) | ||
| any_sep = f'[{escaped_seps}]' if len(seps) > 1 else escaped_seps | ||
| not_sep = f'[^{escaped_seps}]' | ||
|
|
@@ -312,9 +313,12 @@ def translate(pat, *, recursive=False, include_hidden=False, seps=None): | |
| if part: | ||
| if not include_hidden and part[0] in '*?': | ||
| results.append(r'(?!\.)') | ||
|
|
||
| results.extend(fnmatch._translate(part, f'{not_sep}*', not_sep)[0]) | ||
|
|
||
| if idx < last_part_idx: | ||
| results.append(any_sep) | ||
|
|
||
| res = ''.join(results) | ||
| return fr'(?s:{res})\Z' | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -514,6 +514,8 @@ def fn(pat): | |
| self.assertEqual(fn('foo/bar\\baz'), r'(?s:foo[/\\]bar[/\\]baz)\Z') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More generally, can you upodate |
||
| self.assertEqual(fn('**/*'), r'(?s:(?:.+[/\\])?[^/\\]+)\Z') | ||
|
|
||
| self.assertEqual(fn('foo[%-0]bar'), r'(?s:foo(?!)[%-0]bar)\Z') | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Glob.translate escapes regex ranges that ecompass path seperator. |
Uh oh!
There was an error while loading. Please reload this page.