summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-10-01 18:25:29 +0100
committerAndreas Kling <kling@serenityos.org>2022-10-02 21:32:49 +0200
commitb9220a18d1799ecee0d5237dbaddfc185a929827 (patch)
treea1af35851d5597ee22ee2d138f9eebec8a3eaf15
parentfb21271334efb700ca8482e9b49500d9b127d9ba (diff)
downloadserenity-b9220a18d1799ecee0d5237dbaddfc185a929827.zip
LibWeb: Replace incorrect uses of String::trim_whitespace()
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp3
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp3
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp7
-rw-r--r--Userland/Libraries/LibWeb/Infra/CharacterTypes.h2
4 files changed, 10 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index d6b11b1124..69b307a36a 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -13,6 +13,7 @@
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/HTMLFormElement.h>
#include <LibWeb/HTML/HTMLInputElement.h>
+#include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/ButtonBox.h>
#include <LibWeb/Layout/CheckBox.h>
@@ -300,7 +301,7 @@ String HTMLInputElement::value_sanitization_algorithm(String value) const
if (!(c == '\r' || c == '\n'))
builder.append(c);
}
- return builder.to_string().trim_whitespace();
+ return builder.string_view().trim(Infra::ASCII_WHITESPACE);
}
} else if (type_state() == HTMLInputElement::TypeAttributeState::Number) {
// If the value of the element is not a valid floating-point number, then set it to the empty string instead.
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
index d577473a57..30022010d0 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
@@ -13,6 +13,7 @@
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/HTML/HTMLScriptElement.h>
#include <LibWeb/HTML/HTMLSelectElement.h>
+#include <LibWeb/Infra/CharacterTypes.h>
#include <ctype.h>
namespace Web::HTML {
@@ -97,7 +98,7 @@ static String strip_and_collapse_whitespace(StringView string)
}
// ...and then remove any leading and trailing ASCII whitespace from that string.
- return builder.to_string().trim_whitespace();
+ return builder.to_string().trim(Infra::ASCII_WHITESPACE);
}
static void concatenate_descendants_text_content(DOM::Node const* node, StringBuilder& builder)
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
index 63d3b15a3e..59368620c0 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
@@ -15,6 +15,7 @@
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/HTMLScriptElement.h>
#include <LibWeb/HTML/Scripting/ClassicScript.h>
+#include <LibWeb/Infra/CharacterTypes.h>
#include <LibWeb/Loader/ResourceLoader.h>
namespace Web::HTML {
@@ -168,7 +169,7 @@ void HTMLScriptElement::prepare_script()
}
// Determine the script's type as follows:
- if (is_javascript_mime_type_essence_match(script_block_type.trim_whitespace())) {
+ if (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)) {
@@ -222,8 +223,8 @@ void HTMLScriptElement::prepare_script()
auto event = attribute(HTML::AttributeNames::event);
// 3. Strip leading and trailing ASCII whitespace from event and for.
- for_ = for_.trim_whitespace();
- event = event.trim_whitespace();
+ for_ = for_.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. The script is not executed.
if (!for_.equals_ignoring_case("window"sv)) {
diff --git a/Userland/Libraries/LibWeb/Infra/CharacterTypes.h b/Userland/Libraries/LibWeb/Infra/CharacterTypes.h
index e73ff470e9..d9156241cf 100644
--- a/Userland/Libraries/LibWeb/Infra/CharacterTypes.h
+++ b/Userland/Libraries/LibWeb/Infra/CharacterTypes.h
@@ -10,6 +10,8 @@
namespace Web::Infra {
+constexpr auto ASCII_WHITESPACE = "\t\n\f\r "sv;
+
// https://infra.spec.whatwg.org/#ascii-whitespace
constexpr bool is_ascii_whitespace(u32 code_point)
{