LibWeb: Fix checks for elements in XMLDocumentBuilder
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.
This commit is contained in:
parent
bbba484a7e
commit
cfb9c5bb0e
Notes:
sideshowbarker
2024-07-16 22:16:50 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/cfb9c5bb0e Pull-request: https://github.com/SerenityOS/serenity/pull/23233 Issue: https://github.com/SerenityOS/serenity/issues/22305
1 changed files with 3 additions and 3 deletions
|
@ -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,
|
// 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.
|
// 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.
|
// 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);
|
auto& script_element = static_cast<HTML::HTMLScriptElement&>(*node);
|
||||||
script_element.set_parser_document(Badge<XMLDocumentBuilder> {}, m_document);
|
script_element.set_parser_document(Badge<XMLDocumentBuilder> {}, m_document);
|
||||||
script_element.set_force_async(Badge<XMLDocumentBuilder> {}, false);
|
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).
|
// 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));
|
MUST(static_cast<HTML::HTMLTemplateElement&>(*m_current_node).content()->append_child(node));
|
||||||
} else {
|
} else {
|
||||||
|
@ -104,7 +104,7 @@ void XMLDocumentBuilder::element_end(const XML::Name& name)
|
||||||
VERIFY(m_current_node->node_name().equals_ignoring_ascii_case(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 an XML parser with XML scripting support enabled creates a script element, [...]
|
||||||
// When the element's end tag is subsequently parsed,
|
// 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,
|
// the user agent must perform a microtask checkpoint,
|
||||||
HTML::perform_a_microtask_checkpoint();
|
HTML::perform_a_microtask_checkpoint();
|
||||||
// and then prepare the script element.
|
// and then prepare the script element.
|
||||||
|
|
Loading…
Add table
Reference in a new issue