mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Fix is_valid_status_text
to handle UTF-8 correctly
This change fixed a WPT subtest which I also imported.
This commit is contained in:
parent
9c76260756
commit
7bb7edd6df
Notes:
github-actions[bot]
2024-12-15 08:34:26 +00:00
Author: https://github.com/F3n67u
Commit: 7bb7edd6df
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2909
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/shannonbooth ✅
4 changed files with 95 additions and 2 deletions
|
@ -85,13 +85,13 @@ GC::Ref<Response> Response::create(JS::Realm& realm, GC::Ref<Infrastructure::Res
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://httpwg.org/specs/rfc9112.html#status.line
|
// https://httpwg.org/specs/rfc9112.html#status.line
|
||||||
static bool is_valid_status_text(StringView status_text)
|
static bool is_valid_status_text(String const& status_text)
|
||||||
{
|
{
|
||||||
// A status text is valid if it is either the empty string or matches the reason-phrase token production.
|
// A status text is valid if it is either the empty string or matches the reason-phrase token production.
|
||||||
// reason-phrase = 1*( HTAB / SP / VCHAR / obs-text )
|
// reason-phrase = 1*( HTAB / SP / VCHAR / obs-text )
|
||||||
// VCHAR = %x21-7E
|
// VCHAR = %x21-7E
|
||||||
// obs-text = %x80-FF
|
// obs-text = %x80-FF
|
||||||
return all_of(status_text, [](auto c) {
|
return all_of(status_text.code_points(), [](auto c) {
|
||||||
return c == '\t' || c == ' ' || (c >= 0x21 && c <= 0x7E) || (c >= 0x80 && c <= 0xFF);
|
return c == '\t' || c == ' ' || (c >= 0x21 && c <= 0x7E) || (c >= 0x80 && c <= 0xFF);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
Harness status: OK
|
||||||
|
|
||||||
|
Found 9 tests
|
||||||
|
|
||||||
|
9 Pass
|
||||||
|
Pass Check default value for type attribute
|
||||||
|
Pass Check default value for url attribute
|
||||||
|
Pass Check default value for ok attribute
|
||||||
|
Pass Check default value for status attribute
|
||||||
|
Pass Check default value for statusText attribute
|
||||||
|
Pass Check default value for body attribute
|
||||||
|
Pass Check status init values and associated getter
|
||||||
|
Pass Check statusText init values and associated getter
|
||||||
|
Pass Test that Response.headers has the [SameObject] extended attribute
|
|
@ -0,0 +1,15 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset=utf-8>
|
||||||
|
<title>Response init: simple cases</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/response/response-init-001.any.js"></script>
|
|
@ -0,0 +1,64 @@
|
||||||
|
// META: global=window,worker
|
||||||
|
// META: title=Response init: simple cases
|
||||||
|
|
||||||
|
var defaultValues = { "type" : "default",
|
||||||
|
"url" : "",
|
||||||
|
"ok" : true,
|
||||||
|
"status" : 200,
|
||||||
|
"statusText" : "",
|
||||||
|
"body" : null
|
||||||
|
};
|
||||||
|
|
||||||
|
var statusCodes = { "givenValues" : [200, 300, 400, 500, 599],
|
||||||
|
"expectedValues" : [200, 300, 400, 500, 599]
|
||||||
|
};
|
||||||
|
var statusTexts = { "givenValues" : ["", "OK", "with space", String.fromCharCode(0x80)],
|
||||||
|
"expectedValues" : ["", "OK", "with space", String.fromCharCode(0x80)]
|
||||||
|
};
|
||||||
|
var initValuesDict = { "status" : statusCodes,
|
||||||
|
"statusText" : statusTexts
|
||||||
|
};
|
||||||
|
|
||||||
|
function isOkStatus(status) {
|
||||||
|
return 200 <= status && 299 >= status;
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = new Response();
|
||||||
|
for (var attributeName in defaultValues) {
|
||||||
|
test(function() {
|
||||||
|
var expectedValue = defaultValues[attributeName];
|
||||||
|
assert_equals(response[attributeName], expectedValue,
|
||||||
|
"Expect default response." + attributeName + " is " + expectedValue);
|
||||||
|
}, "Check default value for " + attributeName + " attribute");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var attributeName in initValuesDict) {
|
||||||
|
test(function() {
|
||||||
|
var valuesToTest = initValuesDict[attributeName];
|
||||||
|
for (var valueIdx in valuesToTest["givenValues"]) {
|
||||||
|
var givenValue = valuesToTest["givenValues"][valueIdx];
|
||||||
|
var expectedValue = valuesToTest["expectedValues"][valueIdx];
|
||||||
|
var responseInit = {};
|
||||||
|
responseInit[attributeName] = givenValue;
|
||||||
|
var response = new Response("", responseInit);
|
||||||
|
assert_equals(response[attributeName], expectedValue,
|
||||||
|
"Expect response." + attributeName + " is " + expectedValue +
|
||||||
|
" when initialized with " + givenValue);
|
||||||
|
assert_equals(response.ok, isOkStatus(response.status),
|
||||||
|
"Expect response.ok is " + isOkStatus(response.status));
|
||||||
|
}
|
||||||
|
}, "Check " + attributeName + " init values and associated getter");
|
||||||
|
}
|
||||||
|
|
||||||
|
test(function() {
|
||||||
|
const response1 = new Response("");
|
||||||
|
assert_equals(response1.headers, response1.headers);
|
||||||
|
|
||||||
|
const response2 = new Response("", {"headers": {"X-Foo": "bar"}});
|
||||||
|
assert_equals(response2.headers, response2.headers);
|
||||||
|
const headers = response2.headers;
|
||||||
|
response2.headers.set("X-Foo", "quux");
|
||||||
|
assert_equals(headers, response2.headers);
|
||||||
|
headers.set("X-Other-Header", "baz");
|
||||||
|
assert_equals(headers, response2.headers);
|
||||||
|
}, "Test that Response.headers has the [SameObject] extended attribute");
|
Loading…
Add table
Add a link
Reference in a new issue