From dae055220269acfd9866a5db968438bae0a5ac2c Mon Sep 17 00:00:00 2001 From: chu Date: Fri, 22 May 2026 22:55:12 +0800 Subject: [PATCH] fix: escape all control characters in TOML basic strings escapeTomlBasicString only handled \b \t \n \f \r but not other control characters in U+0000-U+001F and U+007F. Per the TOML spec, basic strings may only contain certain escape sequences; unescaped control chars produce invalid TOML that smol-toml cannot parse, silently corrupting the config on next load. Co-Authored-By: Claude Opus 4.7 --- apps/kimi-code/src/tui/config.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/kimi-code/src/tui/config.ts b/apps/kimi-code/src/tui/config.ts index e09774a40e..37686134a0 100644 --- a/apps/kimi-code/src/tui/config.ts +++ b/apps/kimi-code/src/tui/config.ts @@ -149,5 +149,8 @@ function escapeTomlBasicString(value: string): string { .replaceAll('\t', '\\t') .replaceAll('\n', '\\n') .replaceAll('\f', '\\f') - .replaceAll('\r', '\\r'); + .replaceAll('\r', '\\r') + .replaceAll(/[\x00-\x08\x0b\x0e-\x1f\x7f]/g, (ch) => + `\\u${ch.charCodeAt(0).toString(16).padStart(4, '0')}`, + ); }