Skip to content

Commit 62c2fe8

Browse files
authored
Merge pull request #1020 from NVIDIA/yashraj/markdown-list-fence-boundary
fix: end Markdown fenced commands at their list boundary
2 parents 6957e83 + 28e593c commit 62c2fe8

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8306,6 +8306,17 @@ def starts_additional_clause(source: str) -> bool:
83068306
or separator
83078307
):
83088308
table_columns = None
8309+
if fence is not None and leading and indentation < fence[2]:
8310+
# A fenced block inside a list ends when its list container ends.
8311+
# Process this dedented line again as Markdown, rather than letting
8312+
# a prose apostrophe open a shell quote inside the preceding fence.
8313+
if (
8314+
powershell_blocks is not None
8315+
and complete_context
8316+
and fence[3] in {"powershell", "pwsh", "ps1"}
8317+
):
8318+
powershell_blocks.append((fence_body_start, offset))
8319+
fence = None
83098320
if html_end is not None:
83108321
mask_inline_delimiters()
83118322
if (html_end and html_end in leading.lower()) or (not html_end and not leading):

‎tests/nodes/analyzers/test_documentation_reconstruction.py‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,34 @@ def test_nested_list_fence_uses_container_relative_indentation() -> None:
379379
assert "rm -rf /" in projected
380380

381381

382+
@pytest.mark.parametrize("newline", ["\n", "\r\n"])
383+
@pytest.mark.parametrize(
384+
"opening,indent",
385+
[("- ~~~sh", " "), ("- Modes:\n - Commands:\n ~~~sh", " "), ("-\t~~~sh", "\t")],
386+
)
387+
@pytest.mark.parametrize("threat_location", [None, "inside", "after"])
388+
def test_list_fence_dedent_preserves_prose_and_commands(
389+
newline: str, opening: str, indent: str, threat_location: str | None
390+
) -> None:
391+
content = opening + "\n" + indent + "printf ok\n"
392+
if threat_location == "inside":
393+
content += indent + "rm -rf /\n"
394+
content += "\nThe interface doesn't match the spec.\n"
395+
if threat_location == "after":
396+
content += "```sh\nrm -rf /\n```\n"
397+
content += "Ordinary documentation.\n" * 500
398+
content = content.replace("\n", newline)
399+
400+
result = static_runner.run_static_patterns_with_ledger(
401+
{"components": ["guide.md"], "file_cache": {"guide.md": content}}, [tm_module]
402+
)
403+
404+
assert result["inspection_ledger"][0]["outcome"] is LedgerOutcome.COMPLETED
405+
assert any(finding.rule_id == "TM1" for finding in result["findings"]) is (
406+
threat_location is not None
407+
)
408+
409+
382410
@pytest.mark.parametrize("language", ["tcl", "verilog"])
383411
def test_nested_list_fence_keeps_typed_fence_quote_ownership(language: str) -> None:
384412
# A nested list fence takes the same typed-fence path as a top-level fence:
@@ -415,7 +443,11 @@ def test_list_fence_container_relative_indentation_boundary(
415443

416444
@pytest.mark.parametrize("opening,indent", [(" ```sh", " "), ("- - ```sh", " ")])
417445
def test_deeply_indented_marker_does_not_close_fence(opening: str, indent: str) -> None:
418-
content = opening + "\n" + indent + "```\n" + _LITERAL_BACKTICK_COMMAND + "\n```\n"
446+
# Keep the command inside the list; dedenting would itself end its fence.
447+
command_indent = " " if opening.startswith("-") else ""
448+
content = (
449+
opening + "\n" + indent + "```\n" + command_indent + _LITERAL_BACKTICK_COMMAND + "\n```\n"
450+
)
419451
projected = tm_module._markdown_shell_text(content, lambda: None)
420452
assert _LITERAL_BACKTICK_COMMAND in projected
421453

0 commit comments

Comments
 (0)