fix(dashboard): correct TOML round-trip corruption in codex config serializer (#1438)

Integrated into release/v3.7.0. Thanks @benzntech for this great contribution! 🎉 We've removed the unrelated sync-fork.yml file and it's now merged into the release branch.
This commit is contained in:
Benson K B
2026-04-20 05:38:13 +05:30
committed by GitHub
parent 881f59354d
commit 77f326e0dd

View File

@@ -38,9 +38,16 @@ const parseToml = (content: string) => {
// Key = value
const kvMatch = trimmed.match(/^([^=]+)\s*=\s*(.+)$/);
if (kvMatch) {
const key = kvMatch[1].trim();
let key = kvMatch[1].trim();
let value = kvMatch[2].trim();
// Remove quotes
// Strip quotes from key (TOML quoted keys like "gpt-5.3-codex")
if (
(key.startsWith('"') && key.endsWith('"')) ||
(key.startsWith("'") && key.endsWith("'"))
) {
key = key.slice(1, -1);
}
// Remove quotes from string values only (not arrays, booleans, numbers)
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
@@ -58,13 +65,23 @@ const parseToml = (content: string) => {
return result;
};
// Format a TOML value: arrays and booleans stay unquoted, strings get quoted
const formatTomlValue = (value: unknown): string => {
if (typeof value === "boolean") return value ? "true" : "false";
if (typeof value === "number") return String(value);
// Preserve pre-formatted TOML arrays (e.g. ["a", "b"])
if (typeof value === "string" && value.startsWith("[") && value.endsWith("]")) return value;
if (typeof value === "string") return `"${value}"`;
return `"${value}"`;
};
// Convert parsed object back to TOML string
const toToml = (parsed: Record<string, any>) => {
let lines: string[] = [];
// Root level keys
Object.entries(parsed._root).forEach(([key, value]) => {
lines.push(`${key} = "${value}"`);
lines.push(`${key} = ${formatTomlValue(value)}`);
});
// Sections
@@ -73,7 +90,7 @@ const toToml = (parsed: Record<string, any>) => {
lines.push(`[${section}]`);
Object.entries(values).forEach(([key, value]) => {
const formattedKey = key.includes(".") ? `"${key}"` : key;
lines.push(`${formattedKey} = "${value}"`);
lines.push(`${formattedKey} = ${formatTomlValue(value)}`);
});
});