Skip to content

Commit 7b0dfa6

Browse files
committed
LibWeb: Do not move header name/values that are re-used
Fixes a regression from commit: f675cfe
1 parent cbfae97 commit 7b0dfa6

File tree

5 files changed

+121
-2
lines changed

5 files changed

+121
-2
lines changed

Libraries/LibWeb/Fetch/Headers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ WebIDL::ExceptionOr<void> Headers::append(Infrastructure::Header header)
247247

248248
// 2. If temporaryValue is null, then set temporaryValue to value.
249249
if (!temporary_value.has_value()) {
250-
temporary_value = move(value);
250+
temporary_value = value;
251251
}
252252
// 3. Otherwise, set temporaryValue to temporaryValue, followed by 0x2C 0x20, followed by value.
253253
else {
254254
temporary_value = ByteString::formatted("{}, {}", *temporary_value, value);
255255
}
256256

257257
auto temporary_header = Infrastructure::Header {
258-
.name = move(name),
258+
.name = name,
259259
.value = temporary_value.release_value(),
260260
};
261261

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Harness status: OK
2+
3+
Found 27 tests
4+
5+
27 Pass
6+
Pass Loading data…
7+
Pass "no-cors" Headers object cannot have accept set to sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss, , sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
8+
Pass "no-cors" Headers object cannot have accept-language set to sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss, , sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
9+
Pass "no-cors" Headers object cannot have content-language set to sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss, , sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
10+
Pass "no-cors" Headers object cannot have accept set to , sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
11+
Pass "no-cors" Headers object cannot have accept-language set to , sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
12+
Pass "no-cors" Headers object cannot have content-language set to , sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
13+
Pass "no-cors" Headers object cannot have content-type set to text/plain;ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss, text/plain
14+
Pass "no-cors" Headers object cannot have accept/" as header
15+
Pass "no-cors" Headers object cannot have accept/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 as header
16+
Pass "no-cors" Headers object cannot have accept-language/ as header
17+
Pass "no-cors" Headers object cannot have accept-language/@ as header
18+
Pass "no-cors" Headers object cannot have authorization/basics as header
19+
Pass "no-cors" Headers object cannot have content-language/ as header
20+
Pass "no-cors" Headers object cannot have content-language/@ as header
21+
Pass "no-cors" Headers object cannot have content-type/text/html as header
22+
Pass "no-cors" Headers object cannot have content-type/text/plain; long=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901 as header
23+
Pass "no-cors" Headers object cannot have range/bytes 0- as header
24+
Pass "no-cors" Headers object cannot have test/hi as header
25+
Pass "no-cors" Headers object cannot have dpr/2 as header
26+
Pass "no-cors" Headers object cannot have rtt/1.0 as header
27+
Pass "no-cors" Headers object cannot have downlink/-1.0 as header
28+
Pass "no-cors" Headers object cannot have ect/6g as header
29+
Pass "no-cors" Headers object cannot have save-data/on as header
30+
Pass "no-cors" Headers object cannot have viewport-width/100 as header
31+
Pass "no-cors" Headers object cannot have width/100 as header
32+
Pass "no-cors" Headers object cannot have unknown/doesitmatter as header
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
["accept", "\""],
3+
["accept", "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"],
4+
["accept-language", "\u0001"],
5+
["accept-language", "@"],
6+
["authorization", "basics"],
7+
["content-language", "\u0001"],
8+
["content-language", "@"],
9+
["content-type", "text/html"],
10+
["content-type", "text/plain; long=0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"],
11+
["range", "bytes 0-"],
12+
["test", "hi"]
13+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<meta charset=utf-8>
3+
4+
<script>
5+
self.GLOBAL = {
6+
isWindow: function() { return true; },
7+
isWorker: function() { return false; },
8+
isShadowRealm: function() { return false; },
9+
};
10+
</script>
11+
<script src="../../../resources/testharness.js"></script>
12+
<script src="../../../resources/testharnessreport.js"></script>
13+
14+
<div id=log></div>
15+
<script src="../../../fetch/api/headers/headers-no-cors.any.js"></script>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// META: global=window,worker
2+
3+
"use strict";
4+
5+
promise_test(() => fetch("../cors/resources/not-cors-safelisted.json").then(res => res.json().then(runTests)), "Loading data…");
6+
7+
const longValue = "s".repeat(127);
8+
9+
[
10+
{
11+
"headers": ["accept", "accept-language", "content-language"],
12+
"values": [longValue, "", longValue]
13+
},
14+
{
15+
"headers": ["accept", "accept-language", "content-language"],
16+
"values": ["", longValue]
17+
},
18+
{
19+
"headers": ["content-type"],
20+
"values": ["text/plain;" + "s".repeat(116), "text/plain"]
21+
}
22+
].forEach(testItem => {
23+
testItem.headers.forEach(header => {
24+
test(() => {
25+
const noCorsHeaders = new Request("about:blank", { mode: "no-cors" }).headers;
26+
testItem.values.forEach((value) => {
27+
noCorsHeaders.append(header, value);
28+
assert_equals(noCorsHeaders.get(header), testItem.values[0], '1');
29+
});
30+
noCorsHeaders.set(header, testItem.values.join(", "));
31+
assert_equals(noCorsHeaders.get(header), testItem.values[0], '2');
32+
noCorsHeaders.delete(header);
33+
assert_false(noCorsHeaders.has(header));
34+
}, "\"no-cors\" Headers object cannot have " + header + " set to " + testItem.values.join(", "));
35+
});
36+
});
37+
38+
function runTests(testArray) {
39+
testArray = testArray.concat([
40+
["dpr", "2"],
41+
["rtt", "1.0"],
42+
["downlink", "-1.0"],
43+
["ect", "6g"],
44+
["save-data", "on"],
45+
["viewport-width", "100"],
46+
["width", "100"],
47+
["unknown", "doesitmatter"]
48+
]);
49+
testArray.forEach(testItem => {
50+
const [headerName, headerValue] = testItem;
51+
test(() => {
52+
const noCorsHeaders = new Request("about:blank", { mode: "no-cors" }).headers;
53+
noCorsHeaders.append(headerName, headerValue);
54+
assert_false(noCorsHeaders.has(headerName));
55+
noCorsHeaders.set(headerName, headerValue);
56+
assert_false(noCorsHeaders.has(headerName));
57+
}, "\"no-cors\" Headers object cannot have " + headerName + "/" + headerValue + " as header");
58+
});
59+
}

0 commit comments

Comments
 (0)