From d55a14dcce3010c20a06aba1a4eb954312cdff07 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Tue, 10 Oct 2023 22:19:54 -0400 Subject: [PATCH] Escape line filter command properly for `NOMATCH` Join file names using shell aware `shlex.join` Remove string conversion for each file entry in line filter. Escape quotes in line filter using `shlex.quote`. --- post/clang_tidy_review/clang_tidy_review/__init__.py | 7 ++++--- tests/test_review.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/post/clang_tidy_review/clang_tidy_review/__init__.py b/post/clang_tidy_review/clang_tidy_review/__init__.py index e095ea4..3ab4283 100644 --- a/post/clang_tidy_review/clang_tidy_review/__init__.py +++ b/post/clang_tidy_review/clang_tidy_review/__init__.py @@ -20,6 +20,7 @@ import re import io import zipfile +import shlex from github import Github from github.Requester import Requester from github.PaginatedList import PaginatedList @@ -763,12 +764,12 @@ def create_review( # Run clang-tidy with the configured parameters and produce the CLANG_TIDY_FIXES file build_clang_tidy_warnings( - line_ranges, + shlex.quote(line_ranges), build_dir, clang_tidy_checks, clang_tidy_binary, config_file, - '"' + '" "'.join(files) + '"', + shlex.join(files), ) # Read and parse the CLANG_TIDY_FIXES file @@ -887,7 +888,7 @@ def get_line_ranges(diff, files): line_filter_json = [] for name, lines in lines_by_file.items(): - line_filter_json.append(str({"name": name, "lines": lines})) + line_filter_json.append({"name": name, "lines": lines}) return json.dumps(line_filter_json, separators=(",", ":")) diff --git a/tests/test_review.py b/tests/test_review.py index 81a69c8..37256f0 100644 --- a/tests/test_review.py +++ b/tests/test_review.py @@ -231,7 +231,7 @@ def test_filter_files(): def test_line_ranges(): line_ranges = ctr.get_line_ranges(TEST_DIFF, ["src/hello.cxx"]) - expected_line_ranges = """["{'name': 'src/hello.cxx', 'lines': [[5, 16]]}"]""" + expected_line_ranges = '[{"name": "src/hello.cxx", "lines": [[5, 16]]}' assert line_ranges == expected_line_ranges