diff --git a/scripts/tests/test_pr_changed_files.py b/scripts/tests/test_pr_changed_files.py index 1590cd1b4..080fa3de2 100644 --- a/scripts/tests/test_pr_changed_files.py +++ b/scripts/tests/test_pr_changed_files.py @@ -2846,12 +2846,19 @@ def _fold_continuations(lines): at column 0. Verified end to end: a mutant of that exact shape parses as YAML, passes `bash -n`, forms a live `jq -e` — and reddens the guard under this fold while passing under the space-joining one. + + NO `rstrip()`, for the same reason. A backslash followed by trailing whitespace is not a + continuation to bash — the backslash escapes the SPACE — and tolerating it was the one route by + which this fold could DESTROY a `jq` token rather than fabricate one: `ok=y\\` plus invisible + trailing spaces, then a dedented `jq -e ...`, folds to `okyjq -e`, and `\\bjq\\b` finds no word + boundary after the `y`. Every other divergence here over-joins, which can only ever cost a false + positive. Matching the shell exactly is both simpler and the only direction that cannot lose a + `jq`. """ joined, buf = [], "" for ln in lines: - stripped = ln.rstrip() - if stripped.endswith("\\"): - buf += stripped[:-1] + if ln.endswith("\\"): + buf += ln[:-1] else: joined.append(buf + ln) buf = "" @@ -2912,6 +2919,12 @@ def _uses_jq_exit_status(line: str) -> bool: (["a\\", "b\\", "c"], ["abc"]), # two consecutive continuations (["plain", "lines"], ["plain", "lines"]), # nothing to fold (["trailing\\"], ["trailing"]), # continuation with nothing after it + # A backslash followed by whitespace is NOT a continuation — bash escapes the space. + # Nothing bound this before, so dropping the shell-faithfulness survived every other + # case while opening the one route by which the fold can HIDE a `jq` token instead of + # inventing one: `ok=y\` + trailing spaces then a dedented `jq -e` folds to `okyjq -e`, + # and `\\bjq\\b` finds no boundary after the `y`. + (["a\\ ", "b"], ["a\\ ", "b"]), ], ) def test_the_continuation_fold_matches_the_SHELL(raw, folded):