Skip to content

Commit

Permalink
Escape line filter command properly for NOMATCH
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
bwrsandman committed Oct 11, 2023
1 parent e3c07fc commit d55a14d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions post/clang_tidy_review/clang_tidy_review/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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=(",", ":"))


Expand Down
2 changes: 1 addition & 1 deletion tests/test_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit d55a14d

Please sign in to comment.