diff --git a/apps/yaak-client/lib/requestBodyConversion.test.ts b/apps/yaak-client/lib/requestBodyConversion.test.ts index aeebda3ca..1d5a4f008 100644 --- a/apps/yaak-client/lib/requestBodyConversion.test.ts +++ b/apps/yaak-client/lib/requestBodyConversion.test.ts @@ -92,6 +92,21 @@ describe("convertRequestBody", () => { }); }); + test.each(["__proto__", "constructor", "toString"])( + "preserves the form field %s when converting to JSON", + (name) => { + const body = convertRequestBody({ + fromBodyType: BODY_TYPE_FORM_URLENCODED, + toBodyType: BODY_TYPE_JSON, + body: { form: [{ enabled: true, name, value: "hello" }] }, + }); + + expect(body).toEqual({ + text: JSON.stringify({ [name]: "hello" }, null, 2), + }); + }, + ); + test("preserves text when converting to form bodies cannot build form pairs", () => { const body = convertRequestBody({ fromBodyType: BODY_TYPE_XML, diff --git a/apps/yaak-client/lib/requestBodyConversion.ts b/apps/yaak-client/lib/requestBodyConversion.ts index 26cff9938..6b33d49ec 100644 --- a/apps/yaak-client/lib/requestBodyConversion.ts +++ b/apps/yaak-client/lib/requestBodyConversion.ts @@ -161,7 +161,7 @@ function formBodyToUrlEncodedText(form: unknown[]): string { } function formBodyToObject(form: unknown[]) { - const result: Record = {}; + const result: Record = Object.create(null); for (const pair of form) { if (!isRecord(pair)) continue;