From c0285f4a7ea04f3155f9073c4422bfccc6e7d271 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Fri, 20 Dec 2024 12:30:56 +0100 Subject: [PATCH] LibWeb: Do not require visible nodes in the wrap editing algorithm The spec doesn't say they should exist, so we should not `VERIFY_NOT_REACHED()` when they don't. Prevents a crash in the WPT `editing/event.html` tests. --- Libraries/LibWeb/Editing/Internal/Algorithms.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index 54a4946e79c..36cf4aa1e18 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -2638,23 +2638,23 @@ GC::Ptr wrap( // of node list are both inline nodes, and the last child of new parent is not a br, call createElement("br") // on the ownerDocument of new parent and append the result as the last child of new parent. if (!is_inline_node(*new_parent)) { - auto last_visible_child = [&] -> GC::Ref { + auto last_visible_child = [&] -> GC::Ptr { GC::Ptr child = new_parent->last_child(); while (child) { if (is_visible_node(*child)) return *child; child = child->previous_sibling(); } - VERIFY_NOT_REACHED(); + return {}; }(); - auto first_visible_member = [&] -> GC::Ref { + auto first_visible_member = [&] -> GC::Ptr { for (auto& member : node_list) { if (is_visible_node(member)) return member; } - VERIFY_NOT_REACHED(); + return {}; }(); - if (is_inline_node(last_visible_child) && is_inline_node(first_visible_member) + if (last_visible_child && is_inline_node(*last_visible_child) && first_visible_member && is_inline_node(*first_visible_member) && !is(new_parent->last_child())) { auto br_element = MUST(DOM::create_element(*new_parent->owner_document(), HTML::TagNames::br, Namespace::HTML)); MUST(new_parent->append_child(br_element));