diff options
author | Luca Casonato <hello@lcas.dev> | 2022-12-06 09:39:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-06 09:39:04 +0100 |
commit | 923370f18fc936e782ed9515744e675aebb59750 (patch) | |
tree | b994a4eec4b58485ddd6e21dfd37da9b64f7f9ba /cli/tests/unit/fetch_test.ts | |
parent | 3973ceb634afe7b4f38678efe0394da84d9c60a1 (diff) |
fix(ext/fetch): new Request should soft clone (#16869)
Previously the inner request object of the original and the new request
were the same, causing the requests to be entangled and mutable changes
to one to be visible to the other. This fixes that.
Diffstat (limited to 'cli/tests/unit/fetch_test.ts')
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index a668bb480..fde119bf1 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1776,9 +1776,7 @@ Deno.test( Deno.test( { permissions: { net: true } }, - async function fetchBlobUrl(): Promise< - void - > { + async function fetchBlobUrl(): Promise<void> { const blob = new Blob(["ok"], { type: "text/plain" }); const url = URL.createObjectURL(blob); const res = await fetch(url); @@ -1805,3 +1803,28 @@ Deno.test( await promise; }, ); + +Deno.test( + { permissions: { net: true } }, + async function fetchConstructorClones() { + const req = new Request("https://example.com", { + method: "POST", + body: "foo", + }); + assertEquals(await req.text(), "foo"); + await assertRejects(() => req.text()); + + const req2 = new Request(req, { method: "PUT", body: "bar" }); // should not have any impact on req + await assertRejects(() => req.text()); + assertEquals(await req2.text(), "bar"); + + assertEquals(req.method, "POST"); + assertEquals(req2.method, "PUT"); + + assertEquals(req.headers.get("x-foo"), null); + assertEquals(req2.headers.get("x-foo"), null); + req2.headers.set("x-foo", "bar"); // should not have any impact on req + assertEquals(req.headers.get("x-foo"), null); + assertEquals(req2.headers.get("x-foo"), "bar"); + }, +); |