Skip to content

Commit 9fca6bb

Browse files
fix(analyzer): treat a lone carriage return as a line break in quote spans
CommonMark ends a line at a lone CR as well, so a Markdown file with CR line endings could still pair a prose quote with a later command line. A single-line span now contains neither LF nor CR; the CR of a CRLF line ending lies outside such a span, so single-line strings stay complete. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: elliottwaves-20 <[email protected]>
1 parent bbeda8e commit 9fca6bb

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

‎src/skillspector/nodes/analyzers/static_patterns_tool_misuse.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,8 +1674,10 @@ def reconstructs_command(
16741674
owned_word_positions.add(cursor)
16751675
# A span across lines may pair a heredoc or prose quote with a
16761676
# later command line, so only a single-line span ends the word
1677-
# of an expansion inside it.
1678-
if quoted_expansion_starts is not None and "\n" not in content[quote_open:cursor]:
1677+
# of an expansion inside it. A lone carriage return also ends
1678+
# a line in Markdown.
1679+
span = content[quote_open:cursor]
1680+
if quoted_expansion_starts is not None and "\n" not in span and "\r" not in span:
16791681
quoted_expansion_starts.update(pending_quoted_expansions)
16801682
pending_quoted_expansions.clear()
16811683
quote = None

‎tests/nodes/analyzers/test_double_quoted_expansion_word.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ def test_reviewer_script_is_not_fully_inspected() -> None:
176176
('cat <<E\n"a $(date)\nE\n$CMD"" -rf /\necho "\n', "shell"),
177177
('Run "a $(date)\n```sh\n$CMD"" -rf / # "\n```\n', "markdown"),
178178
('Note: "a $(date)\n```bash\n$CMD"" -rf / #"\n```\n', "markdown"),
179+
# A lone carriage return also ends a line in Markdown.
180+
('Run "a $(date)\r```sh\r$CMD"" -rf / # "\r```\r', "markdown"),
181+
('cat <<E\r"a $(date)\rE\r$CMD"" -rf / # "\r', "shell"),
179182
],
180183
ids=[
181184
"heredoc-body",
@@ -187,6 +190,8 @@ def test_reviewer_script_is_not_fully_inspected() -> None:
187190
"heredoc-body-closed-by-later-line",
188191
"markdown-prose-closed-by-comment",
189192
"markdown-note-closed-by-comment",
193+
"markdown-carriage-return-lines",
194+
"heredoc-carriage-return-lines",
190195
],
191196
)
192197
def test_cross_line_quote_pairing_stays_partial(content: str, file_type: str) -> None:

0 commit comments

Comments
 (0)