From 938ffe183e4b27671a626faaead73ca3e336663c Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 3 Jan 2025 16:46:18 +0000 Subject: [PATCH] LibWeb/DOM: Update validate_and_extract to latest spec The "strictly split" infra algorithm feels like an inefficient way of doing basically what our existing split() does, except working with code points instead of bytes. It didn't seem worth it to implement now. --- Libraries/LibWeb/DOM/Element.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 31850a352d..697f396df4 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -205,6 +205,8 @@ WebIDL::ExceptionOr Element::set_attribute(FlyString const& name, String c // https://dom.spec.whatwg.org/#validate-and-extract WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Optional namespace_, FlyString const& qualified_name) { + // To validate and extract a namespace and qualifiedName, run these steps: + // 1. If namespace is the empty string, then set it to null. if (namespace_.has_value() && namespace_.value().is_empty()) namespace_ = {}; @@ -218,11 +220,17 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Option // 4. Let localName be qualifiedName. auto local_name = qualified_name; - // 5. If qualifiedName contains a U+003A (:), then strictly split the string on it and set prefix to the part before and localName to the part after. + // 5. If qualifiedName contains a U+003A (:): if (qualified_name.bytes_as_string_view().contains(':')) { - auto parts = qualified_name.bytes_as_string_view().split_view(':'); - prefix = MUST(FlyString::from_utf8(parts[0])); - local_name = MUST(FlyString::from_utf8(parts[1])); + // 1. Let splitResult be the result of running strictly split given qualifiedName and U+003A (:). + // FIXME: Use the "strictly split" algorithm + auto split_result = qualified_name.bytes_as_string_view().split_view(':'); + + // 2. Set prefix to splitResult[0]. + prefix = MUST(FlyString::from_utf8(split_result[0])); + + // 3. Set localName to splitResult[1]. + local_name = MUST(FlyString::from_utf8(split_result[1])); } // 6. If prefix is non-null and namespace is null, then throw a "NamespaceError" DOMException.