Skip to content

Truly independent web browser

LibWeb: Stop stripping whitespace from the type of a script

Andreas Kling029b70ccc6f7
diff --git a/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
index 371ff02254d..d29e19df92c 100644
--- a/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
@@ -252,9 +252,7 @@ void HTMLScriptElement::prepare_script()
// Otherwise, if el has a type attribute,
else if (maybe_type_attribute.has_value()) {
// then let the script block's type string be the value of that attribute.
- // FIXME: Preserve whitespace in the type string; only the classic JavaScript MIME comparison strips it.
- auto trimmed_type_attribute = maybe_type_attribute->trim(Infra::ASCII_WHITESPACE);
- script_block_type = trimmed_type_attribute;
+ script_block_type = *maybe_type_attribute;
}
// Otherwise, el has a non-empty language attribute;
else if (maybe_language_attribute.has_value() && !maybe_language_attribute->is_empty()) {
@@ -267,7 +265,8 @@ void HTMLScriptElement::prepare_script()
// 9. If the script block's type string is a JavaScript MIME type essence match, or el has a type attribute whose
// value with leading and trailing ASCII whitespace stripped is a JavaScript MIME type essence match,
- if (MimeSniff::is_javascript_mime_type_essence_match(script_block_type)) {
+ if (MimeSniff::is_javascript_mime_type_essence_match(script_block_type)
+ || (maybe_type_attribute.has_value() && MimeSniff::is_javascript_mime_type_essence_match(maybe_type_attribute->trim(Infra::ASCII_WHITESPACE)))) {
// then set el's type to "classic".
m_script_type = ScriptType::Classic;
}
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/module/type.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/module/type.txt
index 6d00483d5ab..44de204c570 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/module/type.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/scripting-1/the-script-element/module/type.txt
@@ -2,11 +2,10 @@ Harness status: OK
Found 6 tests
-3 Pass
-3 Fail
+6 Pass
Pass type="module"
Pass type="MODULE"
Pass type="Module"
-Fail type="module "
-Fail type=" module"
-Fail type=" module "
\ No newline at end of file
+Pass type="module "
+Pass type=" module"
+Pass type=" module "
\ No newline at end of file