Skip to content

Commit 26b6572

Browse files
authored
fix: use 6-backtick fences in summaries to prevent escaping breakage (#17384)
1 parent ee7757b commit 26b6572

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

actions/setup/js/log_parser_shared.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,9 +1524,9 @@ function formatSafeOutputsPreview(safeOutputsContent, options = {}) {
15241524
preview.push("<details>");
15251525
preview.push("<summary>Preview</summary>");
15261526
preview.push("");
1527-
preview.push("```");
1527+
preview.push("``````");
15281528
preview.push(bodyPreview);
1529-
preview.push("```");
1529+
preview.push("``````");
15301530
preview.push("</details>");
15311531
preview.push("");
15321532
}

actions/setup/js/safe_output_summary.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function generateSafeOutputSummary(options) {
6464
// Truncate body if too long
6565
const maxBodyLength = 500;
6666
const bodyPreview = message.body.length > maxBodyLength ? message.body.substring(0, maxBodyLength) + "..." : message.body;
67-
summary += `**Body Preview:**\n\`\`\`\n${bodyPreview}\n\`\`\`\n\n`;
67+
summary += `**Body Preview:**\n\`\`\`\`\`\`\n${bodyPreview}\n\`\`\`\`\`\`\n\n`;
6868
}
6969
if (message.labels && Array.isArray(message.labels)) {
7070
summary += `**Labels:** ${message.labels.join(", ")}\n\n`;
@@ -76,7 +76,7 @@ function generateSafeOutputSummary(options) {
7676

7777
// Add original message details for debugging
7878
if (message) {
79-
summary += `**Message Details:**\n\`\`\`json\n${JSON.stringify(message, null, 2).substring(0, 1000)}\n\`\`\`\n\n`;
79+
summary += `**Message Details:**\n\`\`\`\`\`\`json\n${JSON.stringify(message, null, 2).substring(0, 1000)}\n\`\`\`\`\`\`\n\n`;
8080
}
8181
}
8282

actions/setup/js/safe_output_summary.test.cjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,53 @@ describe("safe_output_summary", () => {
104104
expect(summary.length).toBeLessThan(longBody.length + 1000);
105105
});
106106

107+
it("should use 6-backtick fences for body content containing backticks", () => {
108+
const bodyWithBackticks = "Here is some code:\n```javascript\nconsole.log('hello');\n```\nEnd of body.";
109+
110+
const options = {
111+
type: "create_issue",
112+
messageIndex: 1,
113+
success: true,
114+
result: {
115+
repo: "owner/repo",
116+
number: 123,
117+
},
118+
message: {
119+
title: "Issue with code",
120+
body: bodyWithBackticks,
121+
},
122+
};
123+
124+
const summary = generateSafeOutputSummary(options);
125+
126+
// Should use 6-backtick fences to avoid breaking when body contains triple backticks
127+
expect(summary).toContain("``````\n");
128+
expect(summary).toContain("Body Preview");
129+
expect(summary).toContain("```javascript");
130+
});
131+
132+
it("should use 6-backtick fences for error message details containing backticks", () => {
133+
const messageWithBackticks = {
134+
title: "Test Issue",
135+
body: "Code: ```\nconsole.log('test');\n```",
136+
};
137+
138+
const options = {
139+
type: "create_issue",
140+
messageIndex: 1,
141+
success: false,
142+
result: null,
143+
message: messageWithBackticks,
144+
error: "Failed to create issue",
145+
};
146+
147+
const summary = generateSafeOutputSummary(options);
148+
149+
// Should use 6-backtick fences for message details JSON to avoid rendering issues
150+
expect(summary).toContain("``````json\n");
151+
expect(summary).toContain("Message Details");
152+
});
153+
107154
it("should handle project-specific results", () => {
108155
const options = {
109156
type: "create_project",

0 commit comments

Comments
 (0)