mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 15:04:13 +08:00
fix: Strip ANSI color sequences from tool output
Add stripAnsiCodes function to sanitizer and apply it in formatResultContent to remove terminal color escape codes (e.g., [1;33m for yellow/bold) from tool output before displaying it in GitHub comments. This ensures clean, readable output without raw ANSI escape sequences appearing in the formatted tool results.
This commit is contained in:
@@ -111,6 +111,27 @@ describe("formatResultContent", () => {
|
||||
const result = formatResultContent(JSON.stringify(structuredContent));
|
||||
expect(result).toBe("**→** Hello world\n\n");
|
||||
});
|
||||
|
||||
test("strips ANSI color codes from terminal output", () => {
|
||||
// Test bold yellow warning (the issue reported: [1;33m)
|
||||
const coloredOutput = "\x1B[1;33mWarning: something happened\x1B[0m";
|
||||
const result = formatResultContent(coloredOutput);
|
||||
expect(result).toBe("**→** Warning: something happened\n\n");
|
||||
expect(result).not.toContain("\x1B");
|
||||
expect(result).not.toContain("[1;33m");
|
||||
});
|
||||
|
||||
test("strips ANSI codes from longer output in code blocks", () => {
|
||||
const longColoredOutput =
|
||||
"\x1B[32m✓\x1B[0m Test 1 passed\n" +
|
||||
"\x1B[32m✓\x1B[0m Test 2 passed\n" +
|
||||
"\x1B[31m✗\x1B[0m Test 3 failed\n" +
|
||||
"Some additional output to make it longer";
|
||||
const result = formatResultContent(longColoredOutput);
|
||||
expect(result).toContain("✓ Test 1 passed");
|
||||
expect(result).toContain("✗ Test 3 failed");
|
||||
expect(result).not.toContain("\x1B");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatToolWithResult", () => {
|
||||
|
||||
Reference in New Issue
Block a user