mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 18:41:35 +08:00
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:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user