1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 21:55:07 +00:00

LibWeb: Use is_ascii_case_insensitive_match() where the spec says to

This commit is contained in:
Sam Atkins 2023-02-17 15:21:32 +00:00 committed by Linus Groh
parent f0b72b819e
commit 2026ea557e
10 changed files with 59 additions and 44 deletions

View file

@ -11,6 +11,7 @@
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h> #include <LibWeb/DOM/Element.h>
#include <LibWeb/Infra/Strings.h>
namespace Web::CSS { namespace Web::CSS {
@ -88,7 +89,7 @@ WebIDL::ExceptionOr<void> PropertyOwningCSSStyleDeclaration::set_property(Proper
} }
// 4. If priority is not the empty string and is not an ASCII case-insensitive match for the string "important", then return. // 4. If priority is not the empty string and is not an ASCII case-insensitive match for the string "important", then return.
if (!priority.is_empty() && !priority.equals_ignoring_case("important"sv)) if (!priority.is_empty() && !Infra::is_ascii_case_insensitive_match(priority, "important"sv))
return {}; return {};
// 5. Let component value list be the result of parsing value for property property. // 5. Let component value list be the result of parsing value for property property.

View file

@ -32,6 +32,7 @@
#include <LibWeb/CSS/StyleValue.h> #include <LibWeb/CSS/StyleValue.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/Dump.h> #include <LibWeb/Dump.h>
#include <LibWeb/Infra/Strings.h>
static void log_parse_error(SourceLocation const& location = SourceLocation::current()) static void log_parse_error(SourceLocation const& location = SourceLocation::current())
{ {
@ -1895,7 +1896,7 @@ Optional<Declaration> Parser::consume_a_declaration(TokenStream<T>& tokens)
Optional<size_t> important_index; Optional<size_t> important_index;
for (size_t i = declaration_values.size() - 1; i > 0; i--) { for (size_t i = declaration_values.size() - 1; i > 0; i--) {
auto value = declaration_values[i]; auto value = declaration_values[i];
if (value.is(Token::Type::Ident) && value.token().ident().equals_ignoring_case("important"sv)) { if (value.is(Token::Type::Ident) && Infra::is_ascii_case_insensitive_match(value.token().ident(), "important"sv)) {
important_index = i; important_index = i;
break; break;
} }

View file

@ -63,6 +63,7 @@
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
#include <LibWeb/HTML/WindowProxy.h> #include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h> #include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Layout/BlockFormattingContext.h> #include <LibWeb/Layout/BlockFormattingContext.h>
#include <LibWeb/Layout/InitialContainingBlock.h> #include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/TreeBuilder.h> #include <LibWeb/Layout/TreeBuilder.h>
@ -1270,42 +1271,44 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(DeprecatedSt
// 2. If interface is an ASCII case-insensitive match for any of the strings in the first column in the following table, // 2. If interface is an ASCII case-insensitive match for any of the strings in the first column in the following table,
// then set constructor to the interface in the second column on the same row as the matching string: // then set constructor to the interface in the second column on the same row as the matching string:
auto interface_lowercase = interface.to_lowercase(); if (Infra::is_ascii_case_insensitive_match(interface, "beforeunloadevent"sv)) {
if (interface_lowercase == "beforeunloadevent") {
event = TRY(Event::create(realm, "")); // FIXME: Create BeforeUnloadEvent event = TRY(Event::create(realm, "")); // FIXME: Create BeforeUnloadEvent
} else if (interface_lowercase == "compositionevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "compositionevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create CompositionEvent event = TRY(Event::create(realm, "")); // FIXME: Create CompositionEvent
} else if (interface_lowercase == "customevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "customevent"sv)) {
event = TRY(CustomEvent::create(realm, "")); event = TRY(CustomEvent::create(realm, ""));
} else if (interface_lowercase == "devicemotionevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "devicemotionevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create DeviceMotionEvent event = TRY(Event::create(realm, "")); // FIXME: Create DeviceMotionEvent
} else if (interface_lowercase == "deviceorientationevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "deviceorientationevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create DeviceOrientationEvent event = TRY(Event::create(realm, "")); // FIXME: Create DeviceOrientationEvent
} else if (interface_lowercase == "dragevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "dragevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create DragEvent event = TRY(Event::create(realm, "")); // FIXME: Create DragEvent
} else if (interface_lowercase.is_one_of("event", "events")) { } else if (Infra::is_ascii_case_insensitive_match(interface, "event"sv)
|| Infra::is_ascii_case_insensitive_match(interface, "events"sv)) {
event = TRY(Event::create(realm, "")); event = TRY(Event::create(realm, ""));
} else if (interface_lowercase == "focusevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "focusevent"sv)) {
event = UIEvents::FocusEvent::create(realm, ""); event = UIEvents::FocusEvent::create(realm, "");
} else if (interface_lowercase == "hashchangeevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "hashchangeevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create HashChangeEvent event = TRY(Event::create(realm, "")); // FIXME: Create HashChangeEvent
} else if (interface_lowercase == "htmlevents") { } else if (Infra::is_ascii_case_insensitive_match(interface, "htmlevents"sv)) {
event = TRY(Event::create(realm, "")); event = TRY(Event::create(realm, ""));
} else if (interface_lowercase == "keyboardevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "keyboardevent"sv)) {
event = UIEvents::KeyboardEvent::create(realm, ""); event = UIEvents::KeyboardEvent::create(realm, "");
} else if (interface_lowercase == "messageevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "messageevent"sv)) {
event = TRY(HTML::MessageEvent::create(realm, "")); event = TRY(HTML::MessageEvent::create(realm, ""));
} else if (interface_lowercase.is_one_of("mouseevent", "mouseevents")) { } else if (Infra::is_ascii_case_insensitive_match(interface, "mouseevent"sv)
|| Infra::is_ascii_case_insensitive_match(interface, "mouseevents"sv)) {
event = TRY(UIEvents::MouseEvent::create(realm, "")); event = TRY(UIEvents::MouseEvent::create(realm, ""));
} else if (interface_lowercase == "storageevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "storageevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create StorageEvent event = TRY(Event::create(realm, "")); // FIXME: Create StorageEvent
} else if (interface_lowercase == "svgevents") { } else if (Infra::is_ascii_case_insensitive_match(interface, "svgevents"sv)) {
event = TRY(Event::create(realm, "")); event = TRY(Event::create(realm, ""));
} else if (interface_lowercase == "textevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "textevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create CompositionEvent event = TRY(Event::create(realm, "")); // FIXME: Create CompositionEvent
} else if (interface_lowercase == "touchevent") { } else if (Infra::is_ascii_case_insensitive_match(interface, "touchevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create TouchEvent event = TRY(Event::create(realm, "")); // FIXME: Create TouchEvent
} else if (interface_lowercase.is_one_of("uievent", "uievents")) { } else if (Infra::is_ascii_case_insensitive_match(interface, "uievent"sv)
|| Infra::is_ascii_case_insensitive_match(interface, "uievents"sv)) {
event = UIEvents::UIEvent::create(realm, ""); event = UIEvents::UIEvent::create(realm, "");
} }

View file

@ -36,6 +36,7 @@
#include <LibWeb/HTML/HTMLTextAreaElement.h> #include <LibWeb/HTML/HTMLTextAreaElement.h>
#include <LibWeb/HTML/Parser/HTMLParser.h> #include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/Infra/CharacterTypes.h> #include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Layout/BlockContainer.h> #include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/InitialContainingBlock.h> #include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/InlineNode.h> #include <LibWeb/Layout/InlineNode.h>
@ -1121,7 +1122,8 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(DeprecatedString positio
// 1. Use the first matching item from this list: // 1. Use the first matching item from this list:
// - If position is an ASCII case-insensitive match for the string "beforebegin" // - If position is an ASCII case-insensitive match for the string "beforebegin"
// - If position is an ASCII case-insensitive match for the string "afterend" // - If position is an ASCII case-insensitive match for the string "afterend"
if (position.equals_ignoring_case("beforebegin"sv) || position.equals_ignoring_case("afterend"sv)) { if (Infra::is_ascii_case_insensitive_match(position, "beforebegin"sv)
|| Infra::is_ascii_case_insensitive_match(position, "afterend"sv)) {
// Let context be the context object's parent. // Let context be the context object's parent.
context = this->parent(); context = this->parent();
@ -1131,7 +1133,8 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(DeprecatedString positio
} }
// - If position is an ASCII case-insensitive match for the string "afterbegin" // - If position is an ASCII case-insensitive match for the string "afterbegin"
// - If position is an ASCII case-insensitive match for the string "beforeend" // - If position is an ASCII case-insensitive match for the string "beforeend"
else if (position.equals_ignoring_case("afterbegin"sv) || position.equals_ignoring_case("beforeend"sv)) { else if (Infra::is_ascii_case_insensitive_match(position, "afterbegin"sv)
|| Infra::is_ascii_case_insensitive_match(position, "beforeend"sv)) {
// Let context be the context object. // Let context be the context object.
context = this; context = this;
} }
@ -1162,25 +1165,25 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(DeprecatedString positio
// 4. Use the first matching item from this list: // 4. Use the first matching item from this list:
// - If position is an ASCII case-insensitive match for the string "beforebegin" // - If position is an ASCII case-insensitive match for the string "beforebegin"
if (position.equals_ignoring_case("beforebegin"sv)) { if (Infra::is_ascii_case_insensitive_match(position, "beforebegin"sv)) {
// Insert fragment into the context object's parent before the context object. // Insert fragment into the context object's parent before the context object.
parent()->insert_before(fragment, this); parent()->insert_before(fragment, this);
} }
// - If position is an ASCII case-insensitive match for the string "afterbegin" // - If position is an ASCII case-insensitive match for the string "afterbegin"
else if (position.equals_ignoring_case("afterbegin"sv)) { else if (Infra::is_ascii_case_insensitive_match(position, "afterbegin"sv)) {
// Insert fragment into the context object before its first child. // Insert fragment into the context object before its first child.
insert_before(fragment, first_child()); insert_before(fragment, first_child());
} }
// - If position is an ASCII case-insensitive match for the string "beforeend" // - If position is an ASCII case-insensitive match for the string "beforeend"
else if (position.equals_ignoring_case("beforeend"sv)) { else if (Infra::is_ascii_case_insensitive_match(position, "beforeend"sv)) {
// Append fragment to the context object. // Append fragment to the context object.
TRY(append_child(fragment)); TRY(append_child(fragment));
} }
// - If position is an ASCII case-insensitive match for the string "afterend" // - If position is an ASCII case-insensitive match for the string "afterend"
else if (position.equals_ignoring_case("afterend"sv)) { else if (Infra::is_ascii_case_insensitive_match(position, "afterend"sv)) {
// Insert fragment into the context object's parent before the context object's next sibling. // Insert fragment into the context object's parent before the context object's next sibling.
parent()->insert_before(fragment, next_sibling()); parent()->insert_before(fragment, next_sibling());
} }
@ -1191,7 +1194,7 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(DeprecatedString positio
WebIDL::ExceptionOr<JS::GCPtr<Node>> Element::insert_adjacent(DeprecatedString const& where, JS::NonnullGCPtr<Node> node) WebIDL::ExceptionOr<JS::GCPtr<Node>> Element::insert_adjacent(DeprecatedString const& where, JS::NonnullGCPtr<Node> node)
{ {
// To insert adjacent, given an element element, string where, and a node node, run the steps associated with the first ASCII case-insensitive match for where: // To insert adjacent, given an element element, string where, and a node node, run the steps associated with the first ASCII case-insensitive match for where:
if (where.equals_ignoring_case("beforebegin"sv)) { if (Infra::is_ascii_case_insensitive_match(where, "beforebegin"sv)) {
// -> "beforebegin" // -> "beforebegin"
// If elements parent is null, return null. // If elements parent is null, return null.
if (!parent()) if (!parent())
@ -1201,19 +1204,19 @@ WebIDL::ExceptionOr<JS::GCPtr<Node>> Element::insert_adjacent(DeprecatedString c
return JS::GCPtr<Node> { TRY(parent()->pre_insert(move(node), this)) }; return JS::GCPtr<Node> { TRY(parent()->pre_insert(move(node), this)) };
} }
if (where.equals_ignoring_case("afterbegin"sv)) { if (Infra::is_ascii_case_insensitive_match(where, "afterbegin"sv)) {
// -> "afterbegin" // -> "afterbegin"
// Return the result of pre-inserting node into element before elements first child. // Return the result of pre-inserting node into element before elements first child.
return JS::GCPtr<Node> { TRY(pre_insert(move(node), first_child())) }; return JS::GCPtr<Node> { TRY(pre_insert(move(node), first_child())) };
} }
if (where.equals_ignoring_case("beforeend"sv)) { if (Infra::is_ascii_case_insensitive_match(where, "beforeend"sv)) {
// -> "beforeend" // -> "beforeend"
// Return the result of pre-inserting node into element before null. // Return the result of pre-inserting node into element before null.
return JS::GCPtr<Node> { TRY(pre_insert(move(node), nullptr)) }; return JS::GCPtr<Node> { TRY(pre_insert(move(node), nullptr)) };
} }
if (where.equals_ignoring_case("afterend"sv)) { if (Infra::is_ascii_case_insensitive_match(where, "afterend"sv)) {
// -> "afterend" // -> "afterend"
// If elements parent is null, return null. // If elements parent is null, return null.
if (!parent()) if (!parent())

View file

@ -15,6 +15,7 @@
#include <LibWeb/DOM/Text.h> #include <LibWeb/DOM/Text.h>
#include <LibWeb/DOMParsing/XMLSerializer.h> #include <LibWeb/DOMParsing/XMLSerializer.h>
#include <LibWeb/HTML/HTMLTemplateElement.h> #include <LibWeb/HTML/HTMLTemplateElement.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Namespace.h> #include <LibWeb/Namespace.h>
#include <LibWeb/WebIDL/ExceptionOr.h> #include <LibWeb/WebIDL/ExceptionOr.h>
@ -859,7 +860,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_processing_instruction(DO
if (processing_instruction.target().contains(':')) if (processing_instruction.target().contains(':'))
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target contains a colon"); return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target contains a colon");
if (processing_instruction.target().equals_ignoring_case("xml"sv)) if (Infra::is_ascii_case_insensitive_match(processing_instruction.target(), "xml"sv))
return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target is equal to 'xml'"); return WebIDL::InvalidStateError::create(processing_instruction.realm(), "Processing instruction target is equal to 'xml'");
// 2. If the require well-formed flag is set (its value is true), and node's data contains characters that are not matched by the XML Char production or contains // 2. If the require well-formed flag is set (its value is true), and node's data contains characters that are not matched by the XML Char production or contains

View file

@ -8,6 +8,7 @@
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
#include <LibWeb/Fetch/Infrastructure/NoSniffBlocking.h> #include <LibWeb/Fetch/Infrastructure/NoSniffBlocking.h>
#include <LibWeb/Infra/Strings.h>
namespace Web::Fetch::Infrastructure { namespace Web::Fetch::Infrastructure {
@ -22,7 +23,7 @@ ErrorOr<bool> determine_nosniff(HeaderList const& list)
return false; return false;
// 3. If values[0] is an ASCII case-insensitive match for "nosniff", then return true. // 3. If values[0] is an ASCII case-insensitive match for "nosniff", then return true.
if (!values->is_empty() && values->at(0).equals_ignoring_case("nosniff"sv)) if (!values->is_empty() && Infra::is_ascii_case_insensitive_match(values->at(0), "nosniff"sv))
return true; return true;
// 4. Return false. // 4. Return false.

View file

@ -22,6 +22,7 @@
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
#include <LibWeb/HTML/WindowProxy.h> #include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h> #include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Layout/BreakNode.h> #include <LibWeb/Layout/BreakNode.h>
#include <LibWeb/Layout/InitialContainingBlock.h> #include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/TextNode.h> #include <LibWeb/Layout/TextNode.h>
@ -627,13 +628,13 @@ BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_contex
auto sandboxing_flag_set = active_document()->active_sandboxing_flag_set(); auto sandboxing_flag_set = active_document()->active_sandboxing_flag_set();
// 4. If name is the empty string or an ASCII case-insensitive match for "_self", then set chosen to current. // 4. If name is the empty string or an ASCII case-insensitive match for "_self", then set chosen to current.
if (name.is_empty() || name.equals_ignoring_case("_self"sv)) { if (name.is_empty() || Infra::is_ascii_case_insensitive_match(name, "_self"sv)) {
chosen = this; chosen = this;
} }
// 5. Otherwise, if name is an ASCII case-insensitive match for "_parent", set chosen to current's parent browsing // 5. Otherwise, if name is an ASCII case-insensitive match for "_parent", set chosen to current's parent browsing
// context, if any, and current otherwise. // context, if any, and current otherwise.
else if (name.equals_ignoring_case("_parent"sv)) { else if (Infra::is_ascii_case_insensitive_match(name, "_parent"sv)) {
if (auto parent = this->parent()) if (auto parent = this->parent())
chosen = parent; chosen = parent;
else else
@ -642,7 +643,7 @@ BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_contex
// 6. Otherwise, if name is an ASCII case-insensitive match for "_top", set chosen to current's top-level browsing // 6. Otherwise, if name is an ASCII case-insensitive match for "_top", set chosen to current's top-level browsing
// context, if any, and current otherwise. // context, if any, and current otherwise.
else if (name.equals_ignoring_case("_top"sv)) { else if (Infra::is_ascii_case_insensitive_match(name, "_top"sv)) {
chosen = &top_level_browsing_context(); chosen = &top_level_browsing_context();
} }
@ -652,7 +653,7 @@ BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_contex
// set chosen to that browsing context. If there are multiple matching browsing contexts, the user agent // set chosen to that browsing context. If there are multiple matching browsing contexts, the user agent
// should set chosen to one in some arbitrary consistent manner, such as the most recently opened, most // should set chosen to one in some arbitrary consistent manner, such as the most recently opened, most
// recently focused, or more closely related. // recently focused, or more closely related.
else if (!name.equals_ignoring_case("_blank"sv)) { else if (!Infra::is_ascii_case_insensitive_match(name, "_blank"sv)) {
dbgln("FIXME: Find matching browser context for name {}", name); dbgln("FIXME: Find matching browser context for name {}", name);
chosen = this; chosen = this;
} else { } else {
@ -715,7 +716,7 @@ BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_contex
// FIXME: Our BrowsingContexts do not have SandboxingFlagSets yet, only documents do // FIXME: Our BrowsingContexts do not have SandboxingFlagSets yet, only documents do
// 6. If name is not an ASCII case-insensitive match for "_blank", then set chosen's name to name. // 6. If name is not an ASCII case-insensitive match for "_blank", then set chosen's name to name.
if (!name.equals_ignoring_case("_blank"sv)) if (!Infra::is_ascii_case_insensitive_match(name, "_blank"sv))
chosen->set_name(name); chosen->set_name(name);
} }

View file

@ -8,6 +8,7 @@
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLHyperlinkElementUtils.h> #include <LibWeb/HTML/HTMLHyperlinkElementUtils.h>
#include <LibWeb/Infra/CharacterTypes.h> #include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Loader/FrameLoader.h> #include <LibWeb/Loader/FrameLoader.h>
namespace Web::HTML { namespace Web::HTML {
@ -569,7 +570,7 @@ bool HTMLHyperlinkElementUtils::get_an_elements_noopener(StringView target) cons
// 2. If element's link types do not include the opener keyword and // 2. If element's link types do not include the opener keyword and
// target is an ASCII case-insensitive match for "_blank", then return true. // target is an ASCII case-insensitive match for "_blank", then return true.
if (!link_types.contains_slow("opener"sv) && target.equals_ignoring_case("_blank"sv)) if (!link_types.contains_slow("opener"sv) && Infra::is_ascii_case_insensitive_match(target, "_blank"sv))
return true; return true;
// 3. Return false. // 3. Return false.

View file

@ -18,6 +18,7 @@
#include <LibWeb/HTML/Scripting/ClassicScript.h> #include <LibWeb/HTML/Scripting/ClassicScript.h>
#include <LibWeb/HTML/Scripting/Fetching.h> #include <LibWeb/HTML/Scripting/Fetching.h>
#include <LibWeb/Infra/CharacterTypes.h> #include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/MimeSniff/MimeType.h> #include <LibWeb/MimeSniff/MimeType.h>
@ -189,12 +190,12 @@ void HTMLScriptElement::prepare_script()
m_script_type = ScriptType::Classic; m_script_type = ScriptType::Classic;
} }
// 10. Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "module", // 10. Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "module",
else if (script_block_type.equals_ignoring_case("module"sv)) { else if (Infra::is_ascii_case_insensitive_match(script_block_type, "module"sv)) {
// then set el's type to "module". // then set el's type to "module".
m_script_type = ScriptType::Module; m_script_type = ScriptType::Module;
} }
// 11. Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "importmap", // 11. Otherwise, if the script block's type string is an ASCII case-insensitive match for the string "importmap",
else if (script_block_type.equals_ignoring_case("importmap"sv)) { else if (Infra::is_ascii_case_insensitive_match(script_block_type, "importmap"sv)) {
// then set el's type to "importmap". // then set el's type to "importmap".
m_script_type = ScriptType::ImportMap; m_script_type = ScriptType::ImportMap;
} }
@ -251,13 +252,14 @@ void HTMLScriptElement::prepare_script()
event = event.trim(Infra::ASCII_WHITESPACE); event = event.trim(Infra::ASCII_WHITESPACE);
// 4. If for is not an ASCII case-insensitive match for the string "window", then return. // 4. If for is not an ASCII case-insensitive match for the string "window", then return.
if (!for_.equals_ignoring_case("window"sv)) { if (!Infra::is_ascii_case_insensitive_match(for_, "window"sv)) {
dbgln("HTMLScriptElement: Refusing to run classic script because the provided 'for' attribute is not equal to 'window'"); dbgln("HTMLScriptElement: Refusing to run classic script because the provided 'for' attribute is not equal to 'window'");
return; return;
} }
// 5. If event is not an ASCII case-insensitive match for either the string "onload" or the string "onload()", then return. // 5. If event is not an ASCII case-insensitive match for either the string "onload" or the string "onload()", then return.
if (!event.equals_ignoring_case("onload"sv) && !event.equals_ignoring_case("onload()"sv)) { if (!Infra::is_ascii_case_insensitive_match(event, "onload"sv)
&& !Infra::is_ascii_case_insensitive_match(event, "onload()"sv)) {
dbgln("HTMLScriptElement: Refusing to run classic script because the provided 'event' attribute is not equal to 'onload' or 'onload()'"); dbgln("HTMLScriptElement: Refusing to run classic script because the provided 'event' attribute is not equal to 'onload' or 'onload()'");
return; return;
} }

View file

@ -8,6 +8,7 @@
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLStyleElement.h> #include <LibWeb/HTML/HTMLStyleElement.h>
#include <LibWeb/Infra/Strings.h>
namespace Web::HTML { namespace Web::HTML {
@ -131,7 +132,7 @@ void HTMLStyleElement::update_a_style_block()
// 4. If element's type attribute is present and its value is neither the empty string nor an ASCII case-insensitive match for "text/css", then return. // 4. If element's type attribute is present and its value is neither the empty string nor an ASCII case-insensitive match for "text/css", then return.
auto type_attribute = attribute(HTML::AttributeNames::type); auto type_attribute = attribute(HTML::AttributeNames::type);
if (!type_attribute.is_null() && !type_attribute.is_empty() && !type_attribute.equals_ignoring_case("text/css"sv)) if (!type_attribute.is_null() && !type_attribute.is_empty() && !Infra::is_ascii_case_insensitive_match(type_attribute, "text/css"sv))
return; return;
// FIXME: 5. If the Should element's inline behavior be blocked by Content Security Policy? algorithm returns "Blocked" when executed upon the style element, "style", and the style element's child text content, then return. [CSP] // FIXME: 5. If the Should element's inline behavior be blocked by Content Security Policy? algorithm returns "Blocked" when executed upon the style element, "style", and the style element's child text content, then return. [CSP]