fix(dialog): support wrapped format for Gemini common config

Address audit finding: EditProviderDialog.tsx:121 only parsed flat JSON
format, not the wrapped {"env": {...}} format.

Changes:
- Detect if common config is wrapped or flat format
- Extract env object from either format
- Properly compute difference for live settings extraction

This ensures backward compatibility with existing wrapped-format data.
This commit is contained in:
YoVinchen
2026-01-26 17:13:07 +08:00
parent 1e1080c813
commit d5d7c87fd6
@@ -114,16 +114,24 @@ export function EditProviderDialog({
setLiveSettings(live);
}
} else if (appId === "gemini") {
// Gemini: common config is stored as JSON {"KEY": "VALUE"} format
// Gemini: common config supports two formats:
// - Flat JSON: {"KEY": "VALUE", ...}
// - Wrapped JSON: {"env": {"KEY": "VALUE", ...}}
const liveEnv =
(live as { env?: Record<string, string> }).env ?? {};
// Parse common config as JSON
const commonEnvObj = JSON.parse(
// Parse common config as JSON with format detection
const parsedSnippet = JSON.parse(
commonSnippet.trim(),
) as Record<string, unknown>;
// Check if wrapped format {"env": {...}}
const commonEnvRaw =
parsedSnippet.env &&
typeof parsedSnippet.env === "object"
? (parsedSnippet.env as Record<string, unknown>)
: parsedSnippet;
// Convert to string record, filtering out non-string values
const commonEnvStrObj: Record<string, string> = {};
for (const [key, value] of Object.entries(commonEnvObj)) {
for (const [key, value] of Object.entries(commonEnvRaw)) {
if (typeof value === "string") {
commonEnvStrObj[key] = value;
}