|
1 | 1 | import base64 |
2 | | -import fnmatch |
3 | 2 | import glob |
4 | 3 | import json |
5 | 4 | import mimetypes |
|
29 | 28 | from pydantic import BaseModel, TypeAdapter, ValidationError |
30 | 29 | from syntax_checker import Output as SCOutput |
31 | 30 | from syntax_checker import check_syntax as raw_check_syntax |
| 31 | +from wcmatch import glob as wcglob |
32 | 32 |
|
33 | 33 | from ..client.bash_state.bash_state import ( |
34 | 34 | BashState, |
@@ -570,8 +570,8 @@ def write_file( |
570 | 570 |
|
571 | 571 | # Validate using write_if_empty_mode after checking whitelist |
572 | 572 | allowed_globs = context.bash_state.write_if_empty_mode.allowed_globs |
573 | | - if allowed_globs != "all" and not any( |
574 | | - fnmatch.fnmatch(path_, pattern) for pattern in allowed_globs |
| 573 | + if allowed_globs != "all" and not wcglob.globmatch( |
| 574 | + path_, allowed_globs, flags=wcglob.GLOBSTAR |
575 | 575 | ): |
576 | 576 | return ( |
577 | 577 | f"Error: updating file {path_} not allowed in current mode. Doesn't match allowed globs: {allowed_globs}", |
@@ -762,8 +762,8 @@ def _do_diff_edit( |
762 | 762 |
|
763 | 763 | # Validate using file_edit_mode |
764 | 764 | allowed_globs = context.bash_state.file_edit_mode.allowed_globs |
765 | | - if allowed_globs != "all" and not any( |
766 | | - fnmatch.fnmatch(path_, pattern) for pattern in allowed_globs |
| 765 | + if allowed_globs != "all" and not wcglob.globmatch( |
| 766 | + path_, allowed_globs, flags=wcglob.GLOBSTAR |
767 | 767 | ): |
768 | 768 | raise Exception( |
769 | 769 | f"Error: updating file {path_} not allowed in current mode. Doesn't match allowed globs: {allowed_globs}" |
|
0 commit comments