LibWeb: Make Node::is_text() return true for CDATASection nodes

CDATASection inherits from Text, and so it was incorrect for them to
claim not to be Text nodes.

This fixes at least two WPT subtests. :^)

It also exposed a bug in the DOM Parsing and Serialization spec,
where we're not told how to serialize CDATASection nodes.

Spec bug: https://github.com/w3c/DOM-Parsing/issues/38
This commit is contained in:
Andreas Kling 2024-11-19 15:35:31 +01:00 committed by Tim Ledbetter
parent 564dc0a434
commit 6ffc7ea36d
Notes: github-actions[bot] 2024-11-19 19:25:35 +00:00
5 changed files with 2545 additions and 7 deletions

View file

@ -196,6 +196,14 @@ WebIDL::ExceptionOr<String> serialize_node_to_xml_string_impl(GC::Ref<DOM::Node
return serialize_comment(static_cast<DOM::Comment const&>(*root), require_well_formed);
}
// NOTE: CDATASection comes before Text since CDATASection is a subclass of Text.
if (is<DOM::CDATASection>(*root)) {
// Note: Serialization of CDATASection nodes is not mentioned in the specification, but treating CDATASection nodes as
// text leads to incorrect serialization.
// Spec bug: https://github.com/w3c/DOM-Parsing/issues/38
return serialize_cdata_section(static_cast<DOM::CDATASection const&>(*root), require_well_formed);
}
if (is<DOM::Text>(*root)) {
// -> Text
// Run the algorithm for XML serializing a Text node node.
@ -220,12 +228,6 @@ WebIDL::ExceptionOr<String> serialize_node_to_xml_string_impl(GC::Ref<DOM::Node
return serialize_processing_instruction(static_cast<DOM::ProcessingInstruction const&>(*root), require_well_formed);
}
if (is<DOM::CDATASection>(*root)) {
// Note: Serialization of CDATASection nodes is not mentioned in the specification, but treating CDATASection nodes as
// text leads to incorrect serialization.
return serialize_cdata_section(static_cast<DOM::CDATASection const&>(*root), require_well_formed);
}
if (is<DOM::Attr>(*root)) {
// -> An Attr object
// Return an empty string.