Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/commands/config/getSetReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions tests/actions/getSetReset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down