fix(toml): normalize CJK quotes to prevent parsing errors

Add quote normalization to handle Chinese/fullwidth quotes automatically
converted by IME. This fixes TOML parsing failures when users input
configuration with non-ASCII quotes (" " ' ' etc.).

Changes:
- Add textNormalization utility for quote normalization
- Apply normalization in TOML input handlers (MCP form, Codex config)
- Disable browser auto-correction in Textarea component
- Add defensive normalization in TOML parsing layer
This commit is contained in:
Jason
2025-11-10 14:35:55 +08:00
parent 3210202132
commit 23d06515ad
6 changed files with 52 additions and 13 deletions
+20
View File
@@ -0,0 +1,20 @@
/**
* 将常见的中文/全角/弯引号统一为 ASCII 引号,以避免 TOML 解析失败。
* - 双引号:” “ „ ‟ " → "
* - 单引号:’ ‘ ' → '
* 保守起见,不替换书名号/角引号(《》、「」等),避免误伤内容语义。
*/
export const normalizeQuotes = (text: string): string => {
if (!text) return text;
return text
// 双引号族 → "
.replace(/[“”„‟"]/g, '"')
// 单引号族 → '
.replace(/[‘’']/g, "'");
};
/**
* 专用于 TOML 文本的归一化;目前等同于 normalizeQuotes,后续可扩展(如空白、行尾等)。
*/
export const normalizeTomlText = (text: string): string => normalizeQuotes(text);