diff --git a/src/commands/config/getSetReset.ts b/src/commands/config/getSetReset.ts index b7499316..3f45e6f2 100644 --- a/src/commands/config/getSetReset.ts +++ b/src/commands/config/getSetReset.ts @@ -7,7 +7,12 @@ export class ConfigActions extends BaseAction { } set(keyValue: string): void { - const [key, value] = keyValue.split("="); + // Split on the first "=" only. Config values legitimately contain "=" — + // base64 padding, URLs with a query string — and splitting on every one + // silently stored a truncated value. + const separatorIndex = keyValue.indexOf("="); + const key = separatorIndex === -1 ? "" : keyValue.slice(0, separatorIndex); + const value = separatorIndex === -1 ? undefined : keyValue.slice(separatorIndex + 1); this.startSpinner(`Updating configuration: ${key}`); if (!key || value === undefined) { diff --git a/tests/actions/getSetReset.test.ts b/tests/actions/getSetReset.test.ts index fb0ded72..33cf2833 100644 --- a/tests/actions/getSetReset.test.ts +++ b/tests/actions/getSetReset.test.ts @@ -28,6 +28,27 @@ describe("ConfigActions", () => { expect(configActions["succeedSpinner"]).toHaveBeenCalledWith("Configuration successfully updated"); }); + test("set method keeps '=' inside the value", () => { + configActions.set("apiKey=YWJjZGVm=="); + + expect(configActions["writeConfig"]).toHaveBeenCalledWith("apiKey", "YWJjZGVm=="); + }); + + test("set method keeps a query string intact", () => { + configActions.set("rpcUrl=https://rpc.example.com/v1?key=abc&mode=fast"); + + expect(configActions["writeConfig"]).toHaveBeenCalledWith( + "rpcUrl", + "https://rpc.example.com/v1?key=abc&mode=fast", + ); + }); + + test("set method accepts an empty value", () => { + configActions.set("defaultNetwork="); + + expect(configActions["writeConfig"]).toHaveBeenCalledWith("defaultNetwork", ""); + }); + test("set method fails for invalid format", () => { configActions.set("invalidFormat");