summaryrefslogtreecommitdiffstats
path: root/Tools/c-analyzer/c_analyzer/common/files.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-06-20 08:10:31 (GMT)
committerGitHub <noreply@github.com>2020-06-20 08:10:31 (GMT)
commit935586845815f5b4c7814794413f6a812d4bd45f (patch)
tree69297d0f173d3b42895adb1da65c99f1e021b586 /Tools/c-analyzer/c_analyzer/common/files.py
parenta041e116db5f1e78222cbf2c22aae96457372680 (diff)
downloadcpython-935586845815f5b4c7814794413f6a812d4bd45f.zip
cpython-935586845815f5b4c7814794413f6a812d4bd45f.tar.gz
cpython-935586845815f5b4c7814794413f6a812d4bd45f.tar.bz2
bpo-41043: Escape literal part of the path for glob(). (GH-20994)
Diffstat (limited to 'Tools/c-analyzer/c_analyzer/common/files.py')
-rw-r--r--Tools/c-analyzer/c_analyzer/common/files.py6
1 files changed, 4 insertions, 2 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