From e5d45eeeb14a6c4115c0033dfc2e21774d3ef415 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 4 Oct 2023 17:45:48 +1300 Subject: [PATCH] LibWeb: Properly append attributes to element when creating an Element The main behavioural difference here is that the full qualified name is appended to the element, rather than just the local name and value. --- .../expected/SVG/svg-href-qualified-name.txt | 18 ++++++++++++++ .../input/SVG/svg-href-qualified-name.html | 24 +++++++++++++++++++ .../LibWeb/HTML/Parser/HTMLParser.cpp | 10 +++++--- 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/SVG/svg-href-qualified-name.txt create mode 100644 Tests/LibWeb/Text/input/SVG/svg-href-qualified-name.html diff --git a/Tests/LibWeb/Text/expected/SVG/svg-href-qualified-name.txt b/Tests/LibWeb/Text/expected/SVG/svg-href-qualified-name.txt new file mode 100644 index 0000000000..13e67e7d94 --- /dev/null +++ b/Tests/LibWeb/Text/expected/SVG/svg-href-qualified-name.txt @@ -0,0 +1,18 @@ + --------------- +explicit-xlink-href +--------------- +localName -> href +name -> xlink:href +namespaceURI -> http://www.w3.org/1999/xlink +ownerElement -> explicit-xlink-href +prefix -> xlink +value -> test +--------------- +implicit-xlink-href +--------------- +localName -> href +name -> href +namespaceURI -> null +ownerElement -> implicit-xlink-href +prefix -> null +value -> test diff --git a/Tests/LibWeb/Text/input/SVG/svg-href-qualified-name.html b/Tests/LibWeb/Text/input/SVG/svg-href-qualified-name.html new file mode 100644 index 0000000000..9a93cee23c --- /dev/null +++ b/Tests/LibWeb/Text/input/SVG/svg-href-qualified-name.html @@ -0,0 +1,24 @@ + + + + + + diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 7133108547..bf830e6e8c 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -13,12 +13,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -649,6 +651,7 @@ HTMLParser::AdjustedInsertionLocation HTMLParser::find_appropriate_place_for_ins return adjusted_insertion_location; } +// https://html.spec.whatwg.org/multipage/parsing.html#create-an-element-for-the-token JS::NonnullGCPtr HTMLParser::create_element_for(HTMLToken const& token, Optional const& namespace_, DOM::Node& intended_parent) { // FIXME: 1. If the active speculative HTML parser is not null, then return the result of creating a speculative mock element given given namespace, the tag name of the given token, and the attributes of the given token. @@ -692,9 +695,10 @@ JS::NonnullGCPtr HTMLParser::create_element_for(HTMLToken const& t auto element = create_element(*document, local_name, namespace_, {}, is_value, will_execute_script).release_value_but_fixme_should_propagate_errors(); // 10. Append each attribute in the given token to element. - // FIXME: This isn't the exact `append` the spec is talking about. - token.for_each_attribute([&](auto& attribute) { - MUST(element->set_attribute(attribute.local_name, attribute.value)); + token.for_each_attribute([&](auto const& attribute) { + DOM::QualifiedName qualified_name { attribute.local_name, attribute.prefix, attribute.namespace_ }; + auto dom_attribute = realm().heap().allocate(realm(), *document, move(qualified_name), attribute.value, element); + element->append_attribute(dom_attribute); return IterationDecision::Continue; });