From 657bbd1542ce8fcd3357e5b4dada895229faf834 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 29 Jul 2024 17:22:35 -0400 Subject: [PATCH] LibWeb: Append attributes to the correct element The spec indicates we should append attributes to the top element of the stack of open elements. We were appending the attribute to the bottom. --- Tests/LibWeb/Text/expected/unclosed-html-element.txt | 2 +- Tests/LibWeb/Text/input/unclosed-html-element.html | 2 +- Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Tests/LibWeb/Text/expected/unclosed-html-element.txt b/Tests/LibWeb/Text/expected/unclosed-html-element.txt index aaecaf93c4a..72ef5add63f 100644 --- a/Tests/LibWeb/Text/expected/unclosed-html-element.txt +++ b/Tests/LibWeb/Text/expected/unclosed-html-element.txt @@ -1 +1 @@ -PASS (didn't crash) +HTML element has ' diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 23539578935..bba2efa6644 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -1719,9 +1719,10 @@ void HTMLParser::handle_in_body(HTMLToken& token) // Otherwise, for each attribute on the token, check to see if the attribute is already present on the top element of the stack of open elements. // If it is not, add the attribute and its corresponding value to that element. + auto& top_element = m_stack_of_open_elements.first(); token.for_each_attribute([&](auto& attribute) { - if (!current_node().has_attribute(attribute.local_name)) - current_node().append_attribute(attribute.local_name, attribute.value); + if (!top_element.has_attribute(attribute.local_name)) + top_element.append_attribute(attribute.local_name, attribute.value); return IterationDecision::Continue; }); return;