ソースを参照

LibWeb: Replace incorrect uses of String::trim_whitespace()

Linus Groh 2 年 前
コミット
b9220a18d1

+ 2 - 1
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.

+ 2 - 1
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)

+ 4 - 3
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)) {

+ 2 - 0
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)
 {