LibWeb: Ensure Headers API can handle non-ascii characters

This patch ensure Headers object's associated header list
is ISO-8859-1 encoded when set using `Infra::isomorphic_encode`,
and correctly decoded using `Infra::isomorphic_decode`.

Follow-up of https://github.com/LadybirdBrowser/ladybird/pull/1893
This commit is contained in:
Feng Yu 2024-12-06 09:35:02 -08:00 committed by Andrew Kaster
commit 824e91ffdb
Notes: github-actions[bot] 2024-12-11 23:50:13 +00:00
7 changed files with 188 additions and 13 deletions

View file

@ -0,0 +1,15 @@
<!doctype html>
<meta charset=utf-8>
<title>Headers normalize values</title>
<script>
self.GLOBAL = {
isWindow: function() { return true; },
isWorker: function() { return false; },
isShadowRealm: function() { return false; },
};
</script>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<div id=log></div>
<script src="../../../fetch/api/headers/headers-normalize.any.js"></script>

View file

@ -0,0 +1,56 @@
// META: title=Headers normalize values
// META: global=window,worker
"use strict";
const expectations = {
"name1": [" space ", "space"],
"name2": ["\ttab\t", "tab"],
"name3": [" spaceAndTab\t", "spaceAndTab"],
"name4": ["\r\n newLine", "newLine"], //obs-fold cases
"name5": ["newLine\r\n ", "newLine"],
"name6": ["\r\n\tnewLine", "newLine"],
"name7": ["\t\f\tnewLine\n", "\f\tnewLine"],
"name8": ["newLine\xa0", "newLine\xa0"], // \xa0 == non breaking space
};
test(function () {
const headerDict = Object.fromEntries(
Object.entries(expectations).map(([name, [actual]]) => [name, actual]),
);
var headers = new Headers(headerDict);
for (const name in expectations) {
const expected = expectations[name][1];
assert_equals(
headers.get(name),
expected,
"name: " + name + " has normalized value: " + expected,
);
}
}, "Create headers with not normalized values");
test(function () {
var headers = new Headers();
for (const name in expectations) {
headers.append(name, expectations[name][0]);
const expected = expectations[name][1];
assert_equals(
headers.get(name),
expected,
"name: " + name + " has value: " + expected,
);
}
}, "Check append method with not normalized values");
test(function () {
var headers = new Headers();
for (const name in expectations) {
headers.set(name, expectations[name][0]);
const expected = expectations[name][1];
assert_equals(
headers.get(name),
expected,
"name: " + name + " has value: " + expected,
);
}
}, "Check set method with not normalized values");