From cfab768f958e1ede8f6d3ee5f0130a8395842b86 Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Mon, 26 Jan 2026 15:29:19 +0800 Subject: [PATCH] fix(dialog): unify Gemini common config format parsing Address code audit finding #4: The frontend was incorrectly parsing Gemini common config as KEY=VALUE format while the backend expects JSON format. Unify to use JSON parsing {"KEY": "VALUE"} which matches the format stored by useGeminiCommonConfig. Also add type guard when converting to string record to prevent type assertion issues with non-string values. --- .../providers/EditProviderDialog.tsx | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/components/providers/EditProviderDialog.tsx b/src/components/providers/EditProviderDialog.tsx index 1fa3860e9..cfea4ec18 100644 --- a/src/components/providers/EditProviderDialog.tsx +++ b/src/components/providers/EditProviderDialog.tsx @@ -114,29 +114,27 @@ export function EditProviderDialog({ setLiveSettings(live); } } else if (appId === "gemini") { - // Gemini: 处理 env 格式 + // Gemini: common config is stored as JSON {"KEY": "VALUE"} format const liveEnv = (live as { env?: Record }).env ?? {}; - // 将 env 格式的通用配置转换为对象 - const commonEnvObj: Record = {}; - for (const line of commonSnippet.trim().split("\n")) { - const trimmedLine = line.trim(); - if (trimmedLine && !trimmedLine.startsWith("#")) { - const eqIndex = trimmedLine.indexOf("="); - if (eqIndex > 0) { - const key = trimmedLine.slice(0, eqIndex).trim(); - const value = trimmedLine.slice(eqIndex + 1).trim(); - commonEnvObj[key] = value; - } + // Parse common config as JSON + const commonEnvObj = JSON.parse( + commonSnippet.trim(), + ) as Record; + // Convert to string record, filtering out non-string values + const commonEnvStrObj: Record = {}; + for (const [key, value] of Object.entries(commonEnvObj)) { + if (typeof value === "string") { + commonEnvStrObj[key] = value; } } if ( isPlainObject(liveEnv) && - isPlainObject(commonEnvObj) + isPlainObject(commonEnvStrObj) ) { const { customConfig } = extractDifference( liveEnv, - commonEnvObj, + commonEnvStrObj, ); setLiveSettings({ ...live,