diff --git a/plugins/importer-curl/src/index.ts b/plugins/importer-curl/src/index.ts index 2ab6c5b0..f38370f0 100644 --- a/plugins/importer-curl/src/index.ts +++ b/plugins/importer-curl/src/index.ts @@ -359,7 +359,9 @@ function importCommand(parseEntries: string[], workspaceId: string) { if (typeof p !== "string") { continue; } - const [name, value] = p.split("="); + // splitOnce: a query value may itself contain "=" (a base64 payload, a + // nested filter), and only the first one separates name from value. + const [name, value] = splitOnce(p, "="); urlParameters.push({ name: name ?? "", value: value ?? "", @@ -475,7 +477,9 @@ function importCommand(parseEntries: string[], workspaceId: string) { ...((flagsByName.form as string[] | undefined) || []), ...((flagsByName.F as string[] | undefined) || []), ].map((str) => { - const parts = str.split("="); + // splitOnce for the same reason as --url-query above: base64 padding + // ("...==") and any value containing "=" must survive intact. + const parts = splitOnce(str, "="); const name = parts[0] ?? ""; const value = parts[1] ?? ""; const item: { name: string; value?: string; file?: string; enabled: boolean } = { diff --git a/plugins/importer-curl/tests/index.test.ts b/plugins/importer-curl/tests/index.test.ts index 79d31a07..a2e70c0b 100644 --- a/plugins/importer-curl/tests/index.test.ts +++ b/plugins/importer-curl/tests/index.test.ts @@ -942,6 +942,23 @@ describe("importer-curl", () => { }, }); }); + test("Keeps an = inside a --url-query value", () => { + const imported = convertCurl( + 'curl --url-query "filter=type=book" --url-query "t=eyJhIjoxfQ==" https://yaak.app', + ); + expect(imported.resources.httpRequests?.[0]?.urlParameters).toEqual([ + { enabled: true, name: "filter", value: "type=book" }, + { enabled: true, name: "t", value: "eyJhIjoxfQ==" }, + ]); + }); + + test("Keeps an = inside a form value", () => { + const imported = convertCurl('curl -F "t=eyJhIjoxfQ==" -F "q=a=b" https://yaak.app'); + expect(imported.resources.httpRequests?.[0]?.body?.form).toEqual([ + { enabled: true, name: "t", value: "eyJhIjoxfQ==" }, + { enabled: true, name: "q", value: "a=b" }, + ]); + }); }); const idCount: Partial> = {};