diff options
Diffstat (limited to 'Userland/Libraries')
10 files changed, 59 insertions, 44 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index cfd74f397b..2e0fac1430 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -11,6 +11,7 @@ #include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> +#include <LibWeb/Infra/Strings.h> 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. - if (!priority.is_empty() && !priority.equals_ignoring_case("important"sv)) + if (!priority.is_empty() && !Infra::is_ascii_case_insensitive_match(priority, "important"sv)) return {}; // 5. Let component value list be the result of parsing value for property property. diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index b3456d9ffb..97b1ec2187 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -32,6 +32,7 @@ #include <LibWeb/CSS/StyleValue.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/Dump.h> +#include <LibWeb/Infra/Strings.h> 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; for (size_t i = declaration_values.size() - 1; i > 0; 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; break; } diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index b96826af74..826d7dda9a 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -63,6 +63,7 @@ #include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/WindowProxy.h> #include <LibWeb/HighResolutionTime/TimeOrigin.h> +#include <LibWeb/Infra/Strings.h> #include <LibWeb/Layout/BlockFormattingContext.h> #include <LibWeb/Layout/InitialContainingBlock.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, // 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 (interface_lowercase == "beforeunloadevent") { + if (Infra::is_ascii_case_insensitive_match(interface, "beforeunloadevent"sv)) { 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 - } else if (interface_lowercase == "customevent") { + } else if (Infra::is_ascii_case_insensitive_match(interface, "customevent"sv)) { 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 - } else if (interface_lowercase == "deviceorientationevent") { + } else if (Infra::is_ascii_case_insensitive_match(interface, "deviceorientationevent"sv)) { 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 - } 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, "")); - } else if (interface_lowercase == "focusevent") { + } else if (Infra::is_ascii_case_insensitive_match(interface, "focusevent"sv)) { 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 - } else if (interface_lowercase == "htmlevents") { + } else if (Infra::is_ascii_case_insensitive_match(interface, "htmlevents"sv)) { 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, ""); - } else if (interface_lowercase == "messageevent") { + } else if (Infra::is_ascii_case_insensitive_match(interface, "messageevent"sv)) { 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, "")); - } else if (interface_lowercase == "storageevent") { + } else if (Infra::is_ascii_case_insensitive_match(interface, "storageevent"sv)) { 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, "")); - } else if (interface_lowercase == "textevent") { + } else if (Infra::is_ascii_case_insensitive_match(interface, "textevent"sv)) { 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 - } 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, ""); } diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index c20bac4bd6..14e00f2165 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -36,6 +36,7 @@ #include <LibWeb/HTML/HTMLTextAreaElement.h> #include <LibWeb/HTML/Parser/HTMLParser.h> #include <LibWeb/Infra/CharacterTypes.h> +#include <LibWeb/Infra/Strings.h> #include <LibWeb/Layout/BlockContainer.h> #include <LibWeb/Layout/InitialContainingBlock.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: // - 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.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. 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 "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. context = this; } @@ -1162,25 +1165,25 @@ WebIDL::ExceptionOr<void> Element::insert_adjacent_html(DeprecatedString positio // 4. Use the first matching item from this list: // - 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. parent()->insert_before(fragment, this); } // - 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_before(fragment, first_child()); } // - 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. TRY(append_child(fragment)); } // - 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. 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) { // 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" // If element’s parent is null, return null. 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)) }; } - if (where.equals_ignoring_case("afterbegin"sv)) { + if (Infra::is_ascii_case_insensitive_match(where, "afterbegin"sv)) { // -> "afterbegin" // Return the result of pre-inserting node into element before element’s 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" // Return the result of pre-inserting node into element before null. 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" // If element’s parent is null, return null. if (!parent()) diff --git a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp index c4a8513d47..14aedd50f3 100644 --- a/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp +++ b/Userland/Libraries/LibWeb/DOMParsing/XMLSerializer.cpp @@ -15,6 +15,7 @@ #include <LibWeb/DOM/Text.h> #include <LibWeb/DOMParsing/XMLSerializer.h> #include <LibWeb/HTML/HTMLTemplateElement.h> +#include <LibWeb/Infra/Strings.h> #include <LibWeb/Namespace.h> #include <LibWeb/WebIDL/ExceptionOr.h> @@ -859,7 +860,7 @@ static WebIDL::ExceptionOr<DeprecatedString> serialize_processing_instruction(DO if (processing_instruction.target().contains(':')) 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'"); // 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 diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp index d40d4f759c..1d762df730 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/NoSniffBlocking.cpp @@ -8,6 +8,7 @@ #include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h> #include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h> #include <LibWeb/Fetch/Infrastructure/NoSniffBlocking.h> +#include <LibWeb/Infra/Strings.h> namespace Web::Fetch::Infrastructure { @@ -22,7 +23,7 @@ ErrorOr<bool> determine_nosniff(HeaderList const& list) return false; // 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; // 4. Return false. diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index 0c7230266a..2698c06e32 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -22,6 +22,7 @@ #include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/WindowProxy.h> #include <LibWeb/HighResolutionTime/TimeOrigin.h> +#include <LibWeb/Infra/Strings.h> #include <LibWeb/Layout/BreakNode.h> #include <LibWeb/Layout/InitialContainingBlock.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(); // 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; } // 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. - else if (name.equals_ignoring_case("_parent"sv)) { + else if (Infra::is_ascii_case_insensitive_match(name, "_parent"sv)) { if (auto parent = this->parent()) chosen = parent; 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 // 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(); } @@ -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 // should set chosen to one in some arbitrary consistent manner, such as the most recently opened, most // 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); chosen = this; } else { @@ -715,7 +716,7 @@ BrowsingContext::ChosenBrowsingContext BrowsingContext::choose_a_browsing_contex // 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. - if (!name.equals_ignoring_case("_blank"sv)) + if (!Infra::is_ascii_case_insensitive_match(name, "_blank"sv)) chosen->set_name(name); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp b/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp index df3529abc9..4e2d9ba63a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLHyperlinkElementUtils.cpp @@ -8,6 +8,7 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/HTMLHyperlinkElementUtils.h> #include <LibWeb/Infra/CharacterTypes.h> +#include <LibWeb/Infra/Strings.h> #include <LibWeb/Loader/FrameLoader.h> 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 // 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; // 3. Return false. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index b5fdc0fd2c..caa8a8fb97 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -18,6 +18,7 @@ #include <LibWeb/HTML/Scripting/ClassicScript.h> #include <LibWeb/HTML/Scripting/Fetching.h> #include <LibWeb/Infra/CharacterTypes.h> +#include <LibWeb/Infra/Strings.h> #include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/MimeSniff/MimeType.h> @@ -189,12 +190,12 @@ void HTMLScriptElement::prepare_script() m_script_type = ScriptType::Classic; } // 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". m_script_type = ScriptType::Module; } // 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". m_script_type = ScriptType::ImportMap; } @@ -251,13 +252,14 @@ void HTMLScriptElement::prepare_script() event = event.trim(Infra::ASCII_WHITESPACE); // 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'"); 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()'"); return; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp index 457e33c913..1da797d53e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp @@ -8,6 +8,7 @@ #include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/HTMLStyleElement.h> +#include <LibWeb/Infra/Strings.h> 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. 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; // 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] |