1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

fix(op_crate/fetch): infinite loop on fill headers (#10406)

Fixes a pesky bug in the fetch implementation where if the init part is
specified in `fetch` instead of the `Request` constructor, the
fillHeaders function receives two references to the same object, causing
it to append to the same list being iterated over.
This commit is contained in:
William Perron 2021-04-29 13:56:59 -04:00 committed by GitHub
parent 0ac2a17a0f
commit a50dab683f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -447,6 +447,21 @@ unitTest(
}, },
); );
unitTest(
{ perms: { net: true } },
async function fetchSeparateInit(): Promise<void> {
// related to: https://github.com/denoland/deno/issues/10396
const req = new Request("http://localhost:4545/cli/tests/001_hello.js");
const init = {
method: "GET",
};
req.headers.set("foo", "bar");
const res = await fetch(req, init);
assertEquals(res.status, 200);
await res.text();
},
);
unitTest( unitTest(
{ perms: { net: true } }, { perms: { net: true } },
async function fetchInitTypedArrayBody(): Promise<void> { async function fetchInitTypedArrayBody(): Promise<void> {

View file

@ -247,11 +247,14 @@
// 31. // 31.
if (Object.keys(init).length > 0) { if (Object.keys(init).length > 0) {
let headers = headerListFromHeaders(this[_headers]); let headers = headerListFromHeaders(this[_headers]).slice(
0,
headerListFromHeaders(this[_headers]).length,
);
if (init.headers !== undefined) { if (init.headers !== undefined) {
headers = init.headers; headers = init.headers;
} }
headerListFromHeaders(this[_headers]).slice( headerListFromHeaders(this[_headers]).splice(
0, 0,
headerListFromHeaders(this[_headers]).length, headerListFromHeaders(this[_headers]).length,
); );