mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWeb: Make javascript mime matching spec compliant
When mime essence matching, the spec only asks for a string comparison ignoring ascii case. The whitespace trimming and parsing of the mime produces unexpected and wrong results. Fixes tests on WPT html/semantics/scripting-1/the-script-element :^)
This commit is contained in:
parent
437879f849
commit
cdd78be2d3
Notes:
github-actions[bot]
2024-11-01 22:51:58 +00:00
Author: https://github.com/OHermesJunior
Commit: cdd78be2d3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2046
Reviewed-by: https://github.com/Gingeh
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 28 additions and 40 deletions
|
@ -217,7 +217,7 @@ void HTMLScriptElement::prepare_script()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9. If the script block's type string is a JavaScript MIME type essence match,
|
// 9. If the script block's type string is a JavaScript MIME type essence match,
|
||||||
if (MimeSniff::is_javascript_mime_type_essence_match(MUST(script_block_type.trim(Infra::ASCII_WHITESPACE)))) {
|
if (MimeSniff::is_javascript_mime_type_essence_match(script_block_type)) {
|
||||||
// then set el's type to "classic".
|
// then set el's type to "classic".
|
||||||
m_script_type = ScriptType::Classic;
|
m_script_type = ScriptType::Classic;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,11 @@ namespace Web::MimeSniff {
|
||||||
bool is_javascript_mime_type_essence_match(StringView string)
|
bool is_javascript_mime_type_essence_match(StringView string)
|
||||||
{
|
{
|
||||||
// A string is a JavaScript MIME type essence match if it is an ASCII case-insensitive match for one of the JavaScript MIME type essence strings.
|
// A string is a JavaScript MIME type essence match if it is an ASCII case-insensitive match for one of the JavaScript MIME type essence strings.
|
||||||
// NOTE: The mime type parser automatically lowercases the essence.
|
for (auto const& javascript_essence : s_javascript_mime_type_essence_strings) {
|
||||||
auto type = MimeType::parse(string);
|
if (string.equals_ignoring_ascii_case(javascript_essence))
|
||||||
if (!type.has_value())
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
return type->is_javascript();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool contains_only_http_quoted_string_token_code_points(StringView string)
|
static bool contains_only_http_quoted_string_token_code_points(StringView string)
|
||||||
|
@ -330,40 +330,7 @@ bool MimeType::is_scriptable() const
|
||||||
// https://mimesniff.spec.whatwg.org/#javascript-mime-type
|
// https://mimesniff.spec.whatwg.org/#javascript-mime-type
|
||||||
bool MimeType::is_javascript() const
|
bool MimeType::is_javascript() const
|
||||||
{
|
{
|
||||||
// A JavaScript MIME type is any MIME type whose essence is one of the following:
|
return s_javascript_mime_type_essence_strings.contains_slow(essence());
|
||||||
// - application/ecmascript
|
|
||||||
// - application/javascript
|
|
||||||
// - application/x-ecmascript
|
|
||||||
// - application/x-javascript
|
|
||||||
// - text/ecmascript
|
|
||||||
// - text/javascript
|
|
||||||
// - text/javascript1.0
|
|
||||||
// - text/javascript1.1
|
|
||||||
// - text/javascript1.2
|
|
||||||
// - text/javascript1.3
|
|
||||||
// - text/javascript1.4
|
|
||||||
// - text/javascript1.5
|
|
||||||
// - text/jscript
|
|
||||||
// - text/livescript
|
|
||||||
// - text/x-ecmascript
|
|
||||||
// - text/x-javascript
|
|
||||||
return essence().is_one_of(
|
|
||||||
"application/ecmascript"sv,
|
|
||||||
"application/javascript"sv,
|
|
||||||
"application/x-ecmascript"sv,
|
|
||||||
"application/x-javascript"sv,
|
|
||||||
"text/ecmascript"sv,
|
|
||||||
"text/javascript"sv,
|
|
||||||
"text/javascript1.0"sv,
|
|
||||||
"text/javascript1.1"sv,
|
|
||||||
"text/javascript1.2"sv,
|
|
||||||
"text/javascript1.3"sv,
|
|
||||||
"text/javascript1.4"sv,
|
|
||||||
"text/javascript1.5"sv,
|
|
||||||
"text/jscript"sv,
|
|
||||||
"text/livescript"sv,
|
|
||||||
"text/x-ecmascript"sv,
|
|
||||||
"text/x-javascript"sv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://mimesniff.spec.whatwg.org/#json-mime-type
|
// https://mimesniff.spec.whatwg.org/#json-mime-type
|
||||||
|
|
|
@ -14,6 +14,27 @@ namespace Web::MimeSniff {
|
||||||
|
|
||||||
bool is_javascript_mime_type_essence_match(StringView);
|
bool is_javascript_mime_type_essence_match(StringView);
|
||||||
|
|
||||||
|
// https://mimesniff.spec.whatwg.org/#javascript-mime-type
|
||||||
|
// A JavaScript MIME type is any MIME type whose essence is one of the following:
|
||||||
|
static constexpr Array s_javascript_mime_type_essence_strings = {
|
||||||
|
"application/ecmascript"sv,
|
||||||
|
"application/javascript"sv,
|
||||||
|
"application/x-ecmascript"sv,
|
||||||
|
"application/x-javascript"sv,
|
||||||
|
"text/ecmascript"sv,
|
||||||
|
"text/javascript"sv,
|
||||||
|
"text/javascript1.0"sv,
|
||||||
|
"text/javascript1.1"sv,
|
||||||
|
"text/javascript1.2"sv,
|
||||||
|
"text/javascript1.3"sv,
|
||||||
|
"text/javascript1.4"sv,
|
||||||
|
"text/javascript1.5"sv,
|
||||||
|
"text/jscript"sv,
|
||||||
|
"text/livescript"sv,
|
||||||
|
"text/x-ecmascript"sv,
|
||||||
|
"text/x-javascript"sv
|
||||||
|
};
|
||||||
|
|
||||||
// https://mimesniff.spec.whatwg.org/#mime-type
|
// https://mimesniff.spec.whatwg.org/#mime-type
|
||||||
class MimeType {
|
class MimeType {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue