From fa7d7bd1e4a701d1f5d3ec89f287f30a2dd0babb Mon Sep 17 00:00:00 2001 From: Liz Date: Sat, 30 Sep 2023 01:13:49 +0200 Subject: fix: don't set default request method when creating a Request (#6154) In the case of creating a Request with the parameters `(Request, object)`, there was a bug that method and headers are set from the default created by the init rather then the already present value from the request param. This is because for a to me unknown reason the order in which the parameters are processed is reversed. This fixes that by adding a check which stops the defaults from being set, unless they are explicitly passed. Fixes: https://github.com/oven-sh/bun/issues/6144 --- test/js/web/fetch/fetch.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/js/web/fetch/fetch.test.ts') diff --git a/test/js/web/fetch/fetch.test.ts b/test/js/web/fetch/fetch.test.ts index 85e2296cd..4f7b20d3c 100644 --- a/test/js/web/fetch/fetch.test.ts +++ b/test/js/web/fetch/fetch.test.ts @@ -1241,6 +1241,16 @@ describe("Request", () => { expect(req.signal.aborted).toBe(true); }); + it("copies method (#6144)", () => { + const request = new Request("http://localhost:1337/test", { + method: "POST", + }); + const new_req = new Request(request, { + body: JSON.stringify({ message: "Hello world" }), + }); + expect(new_req.method).toBe("POST"); + }); + it("cloned signal", async () => { gc(); const controller = new AbortController(); -- cgit v1.2.3