From 462f97b28a6797689d9303280e1568638bc4ae45 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 27 Dec 2023 13:28:00 +1300 Subject: [PATCH] LibWeb: Port Element::get_attribute_value from ByteString --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 9 +++++---- Userland/Libraries/LibWeb/DOM/Element.cpp | 6 +++--- Userland/Libraries/LibWeb/DOM/Element.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index f5264c9c437..fe1d562fb93 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -75,6 +75,7 @@ #include #include #include +#include #include static void log_parse_error(SourceLocation const& location = SourceLocation::current()) @@ -6976,11 +6977,11 @@ bool Parser::substitute_attr_function(DOM::Element& element, StringView property // with leading and trailing ASCII whitespace stripped. (No CSS parsing of the value is performed.) // If the attribute value, after trimming, is the empty string, there is instead no substitution value. // If the ’s value is a CSS-wide keyword or `default`, there is instead no substitution value. - auto substitution_value = attribute_value.trim_whitespace(); + auto substitution_value = MUST(attribute_value.trim(Infra::ASCII_WHITESPACE)); if (!substitution_value.is_empty() && !substitution_value.equals_ignoring_ascii_case("default"sv) && !is_css_wide_keyword(substitution_value)) { - dest.empend(Token::create_ident(MUST(FlyString::from_deprecated_fly_string(substitution_value)))); + dest.empend(Token::create_ident(substitution_value)); return true; } } else if (attribute_type.equals_ignoring_ascii_case("length"_fly_string)) { @@ -7016,7 +7017,7 @@ bool Parser::substitute_attr_function(DOM::Element& element, StringView property // The substitution value is a CSS string, whose value is the literal value of the attribute. // (No CSS parsing or "cleanup" of the value is performed.) // No value triggers fallback. - dest.empend(Token::create_string(MUST(FlyString::from_deprecated_fly_string(attribute_value)))); + dest.empend(Token::create_string(attribute_value)); return true; } else if (attribute_type.equals_ignoring_ascii_case("time"_fly_string)) { // Parse a component value from the attribute’s value. @@ -7033,7 +7034,7 @@ bool Parser::substitute_attr_function(DOM::Element& element, StringView property // The substitution value is a CSS value, whose url is the literal value of the attribute. // (No CSS parsing or "cleanup" of the value is performed.) // No value triggers fallback. - dest.empend(Token::create_url(MUST(FlyString::from_deprecated_fly_string(attribute_value)))); + dest.empend(Token::create_url(attribute_value)); return true; } else { // Dimension units diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 43822050ef1..9659dde6fcf 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -130,17 +130,17 @@ ByteString Element::deprecated_get_attribute(StringView name) const } // https://dom.spec.whatwg.org/#concept-element-attributes-get-value -ByteString Element::get_attribute_value(FlyString const& local_name, Optional const& namespace_) const +String Element::get_attribute_value(FlyString const& local_name, Optional const& namespace_) const { // 1. Let attr be the result of getting an attribute given namespace, localName, and element. auto const* attribute = m_attributes->get_attribute_ns(namespace_, local_name); // 2. If attr is null, then return the empty string. if (!attribute) - return ByteString::empty(); + return String {}; // 3. Return attr’s value. - return attribute->value().to_byte_string(); + return attribute->value(); } // https://dom.spec.whatwg.org/#dom-element-getattributenode diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index d1201753524..68690691939 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -103,7 +103,7 @@ public: // FIXME: This should be taking a 'FlyString const&' / 'Optional const&' Optional get_attribute(StringView name) const; ByteString deprecated_get_attribute(StringView name) const; - ByteString get_attribute_value(FlyString const& local_name, Optional const& namespace_ = {}) const; + String get_attribute_value(FlyString const& local_name, Optional const& namespace_ = {}) const; WebIDL::ExceptionOr set_attribute(FlyString const& name, String const& value);