Skip to content

Commit

Permalink
LibWeb: Fix checks for elements in XMLDocumentBuilder
Browse files Browse the repository at this point in the history
Previously, this just checked the tag names. For elements that exist in
different namespaces (like HTMLScriptElement vs SVGScriptElement) this
could lead to invalid casts, as the namespace was not checked.

This switches to using the safer helpers on the DOM::Node.
  • Loading branch information
MacDue authored and kalenikaliaksandr committed Feb 18, 2024
1 parent bbba484 commit cfb9c5b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMap<XML::Name,
// When an XML parser with XML scripting support enabled creates a script element,
// it must have its parser document set and its "force async" flag must be unset.
// FIXME: If the parser was created as part of the XML fragment parsing algorithm, then the element must be marked as "already started" also.
if (m_scripting_support == XMLScriptingSupport::Enabled && HTML::TagNames::script.to_deprecated_fly_string() == name) {
if (m_scripting_support == XMLScriptingSupport::Enabled && node->is_html_script_element()) {
auto& script_element = static_cast<HTML::HTMLScriptElement&>(*node);
script_element.set_parser_document(Badge<XMLDocumentBuilder> {}, m_document);
script_element.set_force_async(Badge<XMLDocumentBuilder> {}, false);
}
if (HTML::TagNames::template_.to_deprecated_fly_string() == m_current_node->node_name().to_deprecated_fly_string()) {
if (m_current_node->is_html_template_element()) {
// When an XML parser would append a node to a template element, it must instead append it to the template element's template contents (a DocumentFragment node).
MUST(static_cast<HTML::HTMLTemplateElement&>(*m_current_node).content()->append_child(node));
} else {
Expand All @@ -104,7 +104,7 @@ void XMLDocumentBuilder::element_end(const XML::Name& name)
VERIFY(m_current_node->node_name().equals_ignoring_ascii_case(name));
// When an XML parser with XML scripting support enabled creates a script element, [...]
// When the element's end tag is subsequently parsed,
if (m_scripting_support == XMLScriptingSupport::Enabled && HTML::TagNames::script.to_deprecated_fly_string() == name) {
if (m_scripting_support == XMLScriptingSupport::Enabled && m_current_node->is_html_script_element()) {
// the user agent must perform a microtask checkpoint,
HTML::perform_a_microtask_checkpoint();
// and then prepare the script element.
Expand Down

0 comments on commit cfb9c5b

Please sign in to comment.