From 24d522afce34f09eb26e2bd25899a95290603c72 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 9 Jul 2025 19:57:53 +1200 Subject: [PATCH] LibWeb/DOM: Avoid passing null to valid name prefix Applies spec change of https://github.com/whatwg/dom/commit/1b4bd48 which we already happened to be doing to avoid crashing. --- Libraries/LibWeb/DOM/Element.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index e6f442523c4..2ce5b5089fb 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -301,11 +301,14 @@ WebIDL::ExceptionOr validate_and_extract(JS::Realm& realm, Option // 3. Set localName to splitResult[1]. local_name = MUST(FlyString::from_utf8(split_result[1])); + + // 4. If prefix is not a valid namespace prefix, then throw an "InvalidCharacterError" DOMException. + if (!is_valid_namespace_prefix(*prefix)) + return WebIDL::InvalidCharacterError::create(realm, "Prefix not a valid namespace prefix."_string); } - // 5. If prefix is not a valid namespace prefix, then throw an "InvalidCharacterError" DOMException. - if (prefix.has_value() && !is_valid_namespace_prefix(*prefix)) - return WebIDL::InvalidCharacterError::create(realm, "Prefix not a valid namespace prefix."_string); + // 5. Assert: prefix is either null or a valid namespace prefix. + ASSERT(!prefix.has_value() || is_valid_namespace_prefix(*prefix)); // 6. If context is "attribute" and localName is not a valid attribute local name, then throw an "InvalidCharacterError" DOMException. if (context == ValidationContext::Attribute && !is_valid_attribute_local_name(local_name))