forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 LadybirdBrowser#1893
- Loading branch information
Showing
7 changed files
with
188 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Tests/LibWeb/Text/expected/Fetch/fetch-headers-non-ascii.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-------------------------------- | ||
Headers constructor | ||
-------------------------------- | ||
Accept: before-æøå-after | ||
X-Test: before-ß-after | ||
|
||
-------------------------------- | ||
Headers.append() | ||
-------------------------------- | ||
Accept: before-æøå-after | ||
X-Test: before-ß-after | ||
|
||
-------------------------------- | ||
Headers.set() | ||
-------------------------------- | ||
Accept: before-æøå-after | ||
X-Test: before-ß-after | ||
|
||
-------------------------------- | ||
Headers.getSetCookie() | ||
-------------------------------- | ||
Set-Cookie: before-æøå-after | ||
|
||
-------------------------------- | ||
Headers iterator | ||
-------------------------------- | ||
accept: before-æøå-after | ||
x-test: before-ß-after | ||
|
||
-------------------------------- | ||
Headers.forEach() | ||
-------------------------------- | ||
accept: before-æøå-after | ||
x-test: before-ß-after |
8 changes: 8 additions & 0 deletions
8
Tests/LibWeb/Text/expected/wpt-import/fetch/api/headers/headers-normalize.any.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Harness status: OK | ||
|
||
Found 3 tests | ||
|
||
3 Pass | ||
Pass Create headers with not normalized values | ||
Pass Check append method with not normalized values | ||
Pass Check set method with not normalized values |
66 changes: 66 additions & 0 deletions
66
Tests/LibWeb/Text/input/Fetch/fetch-headers-non-ascii.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!DOCTYPE html> | ||
<script src="../include.js"></script> | ||
<script> | ||
// This test ensures that the Headers get() methods can handle non-ASCII latin1 characters: code points U+0080-U+00FF. | ||
test(() => { | ||
println("--------------------------------"); | ||
println("Headers constructor") | ||
println("--------------------------------"); | ||
const headers = new Headers({ | ||
"Accept": "before-æøå-after", | ||
"X-Test": "before-ß-after" | ||
}); | ||
println("Accept: " + headers.get("Accept")); | ||
println("X-Test: " + headers.get("X-Test")); | ||
|
||
println("\n--------------------------------"); | ||
println("Headers.append()") | ||
println("--------------------------------"); | ||
const headers2 = new Headers(); | ||
headers2.append("Accept", "before-æøå-after"); | ||
headers2.append("X-Test", "before-ß-after"); | ||
println("Accept: " + headers2.get("Accept")); | ||
println("X-Test: " + headers2.get("X-Test")); | ||
|
||
println("\n--------------------------------"); | ||
println("Headers.set()") | ||
println("--------------------------------"); | ||
const headers3 = new Headers({ | ||
"X-Test": "should be overwritten" | ||
}); | ||
headers3.set("Accept", "before-æøå-after"); | ||
headers3.set("X-Test", "before-ß-after"); | ||
println("Accept: " + headers3.get("Accept")); | ||
println("X-Test: " + headers3.get("X-Test")); | ||
|
||
println("\n--------------------------------"); | ||
println("Headers.getSetCookie()") | ||
println("--------------------------------"); | ||
const headers4 = new Headers({ | ||
"Set-Cookie": "before-æøå-after", | ||
}); | ||
println("Set-Cookie: " + headers4.getSetCookie()); | ||
|
||
println("\n--------------------------------"); | ||
println("Headers iterator") | ||
println("--------------------------------"); | ||
const headers5 = new Headers({ | ||
"Accept": "before-æøå-after", | ||
"X-Test": "before-ß-after" | ||
}); | ||
for (const [key, value] of headers5) { | ||
println(`${key}: ${value}`); | ||
} | ||
|
||
println("\n--------------------------------"); | ||
println("Headers.forEach()") | ||
println("--------------------------------"); | ||
const headers6 = new Headers({ | ||
"Accept": "before-æøå-after", | ||
"X-Test": "before-ß-after" | ||
}); | ||
headers6.forEach((value, key) => { | ||
println(`${key}: ${value}`); | ||
}); | ||
}); | ||
</script> |
15 changes: 15 additions & 0 deletions
15
Tests/LibWeb/Text/input/wpt-import/fetch/api/headers/headers-normalize.any.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
56 changes: 56 additions & 0 deletions
56
Tests/LibWeb/Text/input/wpt-import/fetch/api/headers/headers-normalize.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |