Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/strict-colorfgbg-background.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Ignore malformed COLORFGBG background color indexes during terminal theme detection.
3 changes: 2 additions & 1 deletion apps/kimi-code/src/tui/theme/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ export function parseColorFgBg(value: string | undefined): ResolvedTheme | null
const parts = value.split(";");
const bgRaw = parts.at(-1);
if (bgRaw === undefined) return null;
const bg = parseInt(bgRaw, 10);
if (!/^\d+$/.test(bgRaw)) return null;
const bg = Number.parseInt(bgRaw, 10);
if (!Number.isInteger(bg)) return null;
// ANSI 0=black, 1=red, 2=green, 3=yellow, 4=blue, 5=magenta, 6=cyan, 8=bright black.
const darkBgs = new Set([0, 1, 2, 3, 4, 5, 6, 8]);
Expand Down
9 changes: 9 additions & 0 deletions apps/kimi-code/test/tui/terminal-theme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
handleTerminalThemeInput,
installTerminalThemeTracking,
} from "#/tui/utils/terminal-theme";
import { parseColorFgBg } from "#/tui/theme/detect";

type InputListener = Parameters<TUIState["ui"]["addInputListener"]>[0];
const DARK_OSC11_REPORT = "\u001B]11;rgb:2828/2c2c/3434\u0007";
Expand Down Expand Up @@ -173,3 +174,11 @@ describe('ColorPalette warning token', () => {
expect(getBuiltInPalette('light')).toBe(lightColors);
});
});

describe("parseColorFgBg", () => {
it("rejects malformed background color indexes", () => {
expect(parseColorFgBg("0;9")).toBe("light");
expect(parseColorFgBg("0;9abc")).toBeNull();
expect(parseColorFgBg("0;1.5")).toBeNull();
});
});