LibWeb: Include empty header values when joining duplicated headers

Fixes a regression from commit:
f675cfe90f

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.
This commit is contained in:
Timothy Flynn 2025-11-26 20:05:36 -05:00 committed by Tim Flynn
parent 00070455fd
commit cbfae97101
Notes: github-actions[bot] 2025-11-27 02:23:46 +00:00
3 changed files with 28 additions and 1 deletions

View file

@ -86,14 +86,17 @@ Optional<ByteString> HeaderList::get(StringView name) const
// 2. Return the values of all headers in list whose name is a byte-case-insensitive match for name, separated from
// each other by 0x2C 0x20, in order.
StringBuilder builder;
bool first = true;
for (auto const& header : *this) {
if (!header.name.equals_ignoring_ascii_case(name))
continue;
if (!builder.is_empty())
if (!first)
builder.append(", "sv);
builder.append(header.value);
first = false;
}
return builder.to_byte_string();

View file

@ -0,0 +1,4 @@
X-Foo: ""
X-Foo: ", a"
X-Foo: "a"
X-Foo: "a, "

View file

@ -0,0 +1,20 @@
<!doctype html>
<script src="../include.js"></script>
<script type="text/javascript">
test(() => {
{
let headers = new Headers({ "X-Foo": "" });
println(`X-Foo: "${headers.get("X-Foo")}"`);
headers.append("X-Foo", "a");
println(`X-Foo: "${headers.get("X-Foo")}"`);
}
{
let headers = new Headers({ "X-Foo": "a" });
println(`X-Foo: "${headers.get("X-Foo")}"`);
headers.append("X-Foo", "");
println(`X-Foo: "${headers.get("X-Foo")}"`);
}
});
</script>