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
+5 -3
View File
@@ -1,4 +1,5 @@
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
import { normalizeTomlText } from "@/utils/textNormalization";
import { McpServerSpec } from "../types";
/**
@@ -9,7 +10,8 @@ import { McpServerSpec } from "../types";
export const validateToml = (text: string): string => {
if (!text.trim()) return "";
try {
const parsed = parseToml(text);
const normalized = normalizeTomlText(text);
const parsed = parseToml(normalized);
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
return "mustBeObject";
}
@@ -52,7 +54,7 @@ export const tomlToMcpServer = (tomlText: string): McpServerSpec => {
throw new Error("TOML 内容不能为空");
}
const parsed = parseToml(tomlText);
const parsed = parseToml(normalizeTomlText(tomlText));
// 情况 1: 直接是服务器配置(包含 type/command/url 等字段)
if (
@@ -185,7 +187,7 @@ function normalizeServerConfig(config: any): McpServerSpec {
*/
export const extractIdFromToml = (tomlText: string): string => {
try {
const parsed = parseToml(tomlText);
const parsed = parseToml(normalizeTomlText(tomlText));
// 尝试从 [mcp.servers.<id>] 或 [mcp_servers.<id>] 中提取 ID
if (parsed.mcp && typeof parsed.mcp === "object") {