1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +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

@ -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);
}

View file

@ -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.

View file

@ -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;
}

View file

@ -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]