From b6228507ac10010b124eb00f66ce69995c91b187 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 8 Jun 2023 11:33:24 -0400 Subject: [PATCH] LibXML: Prevent entering the root node of an SVG document twice Currently, if an SVG document is parsed, we enter the root element twice - first when its node is appended, and then immediately after the call to append its node. Prevent this by only ever entering nodes from the appropriate location inside the call to append the node. --- Userland/Libraries/LibXML/Parser/Parser.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibXML/Parser/Parser.cpp b/Userland/Libraries/LibXML/Parser/Parser.cpp index 4a6bce9614..f782b3f3ca 100644 --- a/Userland/Libraries/LibXML/Parser/Parser.cpp +++ b/Userland/Libraries/LibXML/Parser/Parser.cpp @@ -71,7 +71,9 @@ size_t Parser::s_debug_indent_level { 0 }; void Parser::append_node(NonnullOwnPtr node) { if (m_entered_node) { - m_entered_node->content.get().children.append(move(node)); + auto& entered_element = m_entered_node->content.get(); + entered_element.children.append(move(node)); + enter_node(*entered_element.children.last()); } else { m_root_node = move(node); enter_node(*m_root_node); @@ -620,7 +622,6 @@ ErrorOr Parser::parse_element() auto& node = *start_tag; auto& tag = node.content.get(); append_node(move(start_tag)); - enter_node(node); ScopeGuard quit { [&] { leave_node();