LibWeb: Look at both namespace & tag name in HTML parser stack checks

We were neglecting to check the namespace when looking for a specific
type of element on the stack of open elements in many cases.

This caused us to confuse HTML and SVG elements.
This commit is contained in:
Andreas Kling
2024-11-04 17:14:25 +01:00
committed by Andreas Kling
parent 7d7f8f1b48
commit ceedfb34d2
4 changed files with 24 additions and 18 deletions

View File

@@ -7,6 +7,7 @@
#include <LibWeb/DOM/Element.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/Parser/StackOfOpenElements.h>
#include <LibWeb/Namespace.h>
namespace Web::HTML {
@@ -105,10 +106,12 @@ bool StackOfOpenElements::contains(const DOM::Element& element) const
return false;
}
bool StackOfOpenElements::contains(FlyString const& tag_name) const
bool StackOfOpenElements::contains_template_element() const
{
for (auto& element_on_stack : m_elements) {
if (element_on_stack->local_name() == tag_name)
for (auto const& element : m_elements) {
if (element->namespace_uri() != Namespace::HTML)
continue;
if (element->local_name() == HTML::TagNames::template_)
return true;
}
return false;
@@ -116,7 +119,7 @@ bool StackOfOpenElements::contains(FlyString const& tag_name) const
void StackOfOpenElements::pop_until_an_element_with_tag_name_has_been_popped(FlyString const& tag_name)
{
while (m_elements.last()->local_name() != tag_name)
while (m_elements.last()->namespace_uri() != Namespace::HTML || m_elements.last()->local_name() != tag_name)
(void)pop();
(void)pop();
}