From 472b56b47c784404a387004faa84cbbb0b526a05 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 2 Nov 2024 02:57:46 +1300 Subject: [PATCH] LibWeb: Propagate exception if serializing inner node fails Fixing a crash for the given test. --- .../wpt-import/domparsing/innerhtml-01.txt | 13 +++++++++ .../wpt-import/domparsing/innerhtml-01.xhtml | 28 +++++++++++++++++++ Userland/Libraries/LibWeb/DOM/Node.cpp | 7 ++--- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/domparsing/innerhtml-01.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/domparsing/innerhtml-01.xhtml diff --git a/Tests/LibWeb/Text/expected/wpt-import/domparsing/innerhtml-01.txt b/Tests/LibWeb/Text/expected/wpt-import/domparsing/innerhtml-01.txt new file mode 100644 index 00000000000..a1259bee002 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/domparsing/innerhtml-01.txt @@ -0,0 +1,13 @@ +Summary + +Harness status: OK + +Rerun + +Found 2 tests + +1 Pass +1 Fail +Details +Result Test Name MessagePass innerHTML in XHTML: getting while the document is in an invalid state +Fail innerHTML in XHTML: getting while the document is in an invalid state 1 \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/domparsing/innerhtml-01.xhtml b/Tests/LibWeb/Text/input/wpt-import/domparsing/innerhtml-01.xhtml new file mode 100644 index 00000000000..a1c6c692271 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/domparsing/innerhtml-01.xhtml @@ -0,0 +1,28 @@ + + +innerHTML in XHTML: getting while the document is in an invalid state + + + + + + + + +
+ + + diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index bc8031c2089..a39b7f215fc 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -1568,11 +1568,10 @@ WebIDL::ExceptionOr Node::serialize_fragment(DOMParsing::RequireWellForm // For inner, concatenate the serialization of all children. if (fragment_serialization_mode == FragmentSerializationMode::Inner) { StringBuilder markup; - for_each_child([&markup, require_well_formed](auto& child) { - auto child_markup = DOMParsing::serialize_node_to_xml_string(child, require_well_formed).release_value_but_fixme_should_propagate_errors(); + for (auto* child = first_child(); child; child = child->next_sibling()) { + auto child_markup = TRY(DOMParsing::serialize_node_to_xml_string(*child, require_well_formed)); markup.append(child_markup.bytes_as_string_view()); - return IterationDecision::Continue; - }); + } return MUST(markup.to_string()); } return DOMParsing::serialize_node_to_xml_string(*this, require_well_formed);