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
#include
#include
+#include
#include
#include
#include
@@ -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
#include
#include
+#include
#include
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
#include
#include
+#include
#include
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)
{