Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/review/fix-handoff-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,25 @@ export type FixHandoffBlock = {
* parse fix-handoff blocks in a comment body without depending on markdown structure alone. */
const FIX_HANDOFF_MARKER = "<!-- gittensory:fix-handoff -->";

/** Public-safe inline-code escaping for a finding path/location. GitHub comments still render markdown inside
* collapsibles, so neutralize delimiters that can break out of the `...` span or table-like contexts before
* composing the location label. */
function markdownPathCodeText(value: string): string {
return value
.replace(/\\/g, "\\\\")
.replace(/`/g, "\\`")
.replace(/\|/g, "\\|")
.replace(/[<>]/g, (char) => (char === "<" ? "&lt;" : "&gt;"));
}

/** PURE: build a single finding's fix-handoff block. Never throws; a finding whose `line` is not a positive
* integer (0, negative, non-finite — i.e. "no commentable line") still yields a valid PATH-ONLY block rather
* than being dropped, since the finding itself is still actionable context even without a line anchor. */
export function buildFixHandoffBlock(finding: InlineFinding): FixHandoffBlock {
const hasLine = Number.isInteger(finding.line) && finding.line > 0;
const line = hasLine ? finding.line : 0;
const location = hasLine ? `${finding.path}:${line}` : `${finding.path} (no specific line)`;
const safePath = markdownPathCodeText(finding.path);
const location = hasLine ? `${safePath}:${line}` : `${safePath} (no specific line)`;
const label = finding.severity === "blocker" ? "Blocker" : "Nit";
const suggestedChange = finding.suggestion?.trim() || undefined;
const suggestionBlock = suggestedChange ? `\n\nSuggested change:\n\`\`\`\n${suggestedChange}\n\`\`\`` : "";
Expand Down
15 changes: 15 additions & 0 deletions test/unit/fix-handoff-collapsible.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ describe("buildFixHandoffCollapsible (#1962)", () => {
expect(c?.body).toContain("`src/b.ts (no specific line)`");
});

it("escapes adversarial paths before rendering inline-code locations", () => {
const [block] = buildFixHandoffBlocks([
{
path: "src/x` [Review required](https://evil.example/phish) | <tag>",
line: 7,
severity: "blocker",
body: "Check the suspicious path rendering.",
},
]);

expect(block?.path).toBe("src/x` [Review required](https://evil.example/phish) | <tag>");
expect(block?.body).toContain("`src/x\\` [Review required](https://evil.example/phish) \\| &lt;tag&gt;:7`");
expect(block?.body).not.toContain("`src/x` [Review required](https://evil.example/phish) | <tag>:7`");
});

it("carries the no-server-side-write local-execution boundary on every block", () => {
expect(buildFixHandoffCollapsible(blocks)?.body).toContain(LOCAL_WRITE_BOUNDARY);
});
Expand Down