Skip to content

Commit cbfae97

Browse files
committed
LibWeb: Include empty header values when joining duplicated headers
Fixes a regression from commit: f675cfe It is not sufficient to only check if the builder is empty, as we will then drop empty header values (when the first found value is empty). This is tested in WPT by /cors/origin.htm, but that requires an HTTP server.
1 parent 0007045 commit cbfae97

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Libraries/LibWeb/Fetch/Infrastructure/HTTP/Headers.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ Optional<ByteString> HeaderList::get(StringView name) const
8686
// 2. Return the values of all headers in list whose name is a byte-case-insensitive match for name, separated from
8787
// each other by 0x2C 0x20, in order.
8888
StringBuilder builder;
89+
bool first = true;
8990

9091
for (auto const& header : *this) {
9192
if (!header.name.equals_ignoring_ascii_case(name))
9293
continue;
9394

94-
if (!builder.is_empty())
95+
if (!first)
9596
builder.append(", "sv);
97+
9698
builder.append(header.value);
99+
first = false;
97100
}
98101

99102
return builder.to_byte_string();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
X-Foo: ""
2+
X-Foo: ", a"
3+
X-Foo: "a"
4+
X-Foo: "a, "
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<script src="../include.js"></script>
3+
<script type="text/javascript">
4+
test(() => {
5+
{
6+
let headers = new Headers({ "X-Foo": "" });
7+
println(`X-Foo: "${headers.get("X-Foo")}"`);
8+
9+
headers.append("X-Foo", "a");
10+
println(`X-Foo: "${headers.get("X-Foo")}"`);
11+
}
12+
{
13+
let headers = new Headers({ "X-Foo": "a" });
14+
println(`X-Foo: "${headers.get("X-Foo")}"`);
15+
16+
headers.append("X-Foo", "");
17+
println(`X-Foo: "${headers.get("X-Foo")}"`);
18+
}
19+
});
20+
</script>

0 commit comments

Comments
 (0)