mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 14:34:59 +00:00
LibWeb: Implement more close to spec javascript mime type checking
Previously we would simply check the an input string against a list of mime type essences, ignoring that the input might not be a valid mime type or contain parameters. This patch moves the helpers into the MimeSniff namespace and properly parses an input string before comparing the essence.
This commit is contained in:
parent
93464d4e41
commit
297e293a3f
3 changed files with 39 additions and 8 deletions
|
@ -17,6 +17,7 @@
|
|||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||
#include <LibWeb/Infra/CharacterTypes.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
#include <LibWeb/MimeSniff/MimeType.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -108,13 +109,6 @@ void HTMLScriptElement::execute_script()
|
|||
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::load));
|
||||
}
|
||||
|
||||
// https://mimesniff.spec.whatwg.org/#javascript-mime-type-essence-match
|
||||
static bool is_javascript_mime_type_essence_match(String const& string)
|
||||
{
|
||||
auto lowercase_string = string.to_lowercase();
|
||||
return lowercase_string.is_one_of("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");
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script
|
||||
void HTMLScriptElement::prepare_script()
|
||||
{
|
||||
|
@ -169,7 +163,7 @@ void HTMLScriptElement::prepare_script()
|
|||
}
|
||||
|
||||
// Determine the script's type as follows:
|
||||
if (is_javascript_mime_type_essence_match(script_block_type.trim(Infra::ASCII_WHITESPACE))) {
|
||||
if (MimeSniff::is_javascript_mime_type_essence_match(script_block_type.trim(Infra::ASCII_WHITESPACE))) {
|
||||
// - If the script block's type string with leading and trailing ASCII whitespace stripped is a JavaScript MIME type essence match, the script's type is "classic".
|
||||
m_script_type = ScriptType::Classic;
|
||||
} else if (script_block_type.equals_ignoring_case("module"sv)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue