diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-07-02 07:05:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-02 07:05:16 (GMT) |
commit | ecfecc2d6ce88ae71c783f0465a508c6a1b2f2b6 (patch) | |
tree | 15fe925d7c2eed5f56154f68971a5883870d5841 /Tools/c-analyzer | |
parent | df59293bf0d815fe37743025d639a63a78e0c771 (diff) | |
download | cpython-ecfecc2d6ce88ae71c783f0465a508c6a1b2f2b6.zip cpython-ecfecc2d6ce88ae71c783f0465a508c6a1b2f2b6.tar.gz cpython-ecfecc2d6ce88ae71c783f0465a508c6a1b2f2b6.tar.bz2 |
[3.9] bpo-41043: Escape literal part of the path for glob(). (GH-20994). (GH-21275)
(cherry picked from commit 935586845815f5b4c7814794413f6a812d4bd45f)
Diffstat (limited to 'Tools/c-analyzer')
-rw-r--r-- | Tools/c-analyzer/c_analyzer/common/files.py | 6 | ||||
-rw-r--r-- | Tools/c-analyzer/check-c-globals.py | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/Tools/c-analyzer/c_analyzer/common/files.py b/Tools/c-analyzer/c_analyzer/common/files.py index ab551a8..f630afe 100644 --- a/Tools/c-analyzer/c_analyzer/common/files.py +++ b/Tools/c-analyzer/c_analyzer/common/files.py @@ -41,6 +41,8 @@ def walk_tree(root, *, def glob_tree(root, *, suffix=None, _glob=glob.iglob, + _escape=glob.escape, + _join=os.path.join, ): """Yield each file in the tree under the given directory name. @@ -51,9 +53,9 @@ def glob_tree(root, *, if not isinstance(suffix, str): raise ValueError('suffix must be a string') - for filename in _glob(f'{root}/*{suffix}'): + for filename in _glob(_join(_escape(root), f'*{suffix}')): yield filename - for filename in _glob(f'{root}/**/*{suffix}'): + for filename in _glob(_join(_escape(root), f'**/*{suffix}')): yield filename diff --git a/Tools/c-analyzer/check-c-globals.py b/Tools/c-analyzer/check-c-globals.py index e68ed92..1371f92 100644 --- a/Tools/c-analyzer/check-c-globals.py +++ b/Tools/c-analyzer/check-c-globals.py @@ -37,7 +37,9 @@ IGNORED_VARS = { def find_capi_vars(root): capi_vars = {} for dirname in SOURCE_DIRS: - for filename in glob.glob(os.path.join(ROOT_DIR, dirname, '**/*.[hc]'), + for filename in glob.glob(os.path.join( + glob.escape(os.path.join(ROOT_DIR, dirname)), + '**/*.[hc]'), recursive=True): with open(filename) as file: for name in _find_capi_vars(file): |