From 8bc3f4c18611c2190d393fc59f008823f002e579 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 21 Mar 2022 19:11:03 +0100 Subject: LibWeb: Fix logic mistakes in Range stringification We were passing the wrong length argument to substring() when stringifying a range where start and end are the same text node. Also, make sure we visit all the contained text nodes when appending them to the output. This was caught by an Acid3 subtest. --- Userland/Libraries/LibWeb/DOM/Range.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Userland/Libraries/LibWeb/DOM') diff --git a/Userland/Libraries/LibWeb/DOM/Range.cpp b/Userland/Libraries/LibWeb/DOM/Range.cpp index e30fee6573..5b2b9bb616 100644 --- a/Userland/Libraries/LibWeb/DOM/Range.cpp +++ b/Userland/Libraries/LibWeb/DOM/Range.cpp @@ -510,15 +510,15 @@ String Range::to_string() const // 2. If this’s start node is this’s end node and it is a Text node, // then return the substring of that Text node’s data beginning at this’s start offset and ending at this’s end offset. if (start_container() == end_container() && is(*start_container())) - return static_cast(*start_container()).data().substring(start_offset(), end_offset()); + return static_cast(*start_container()).data().substring(start_offset(), end_offset() - start_offset()); // 3. If this’s start node is a Text node, then append the substring of that node’s data from this’s start offset until the end to s. if (is(*start_container())) builder.append(static_cast(*start_container()).data().substring_view(start_offset())); // 4. Append the concatenation of the data of all Text nodes that are contained in this, in tree order, to s. - for (Node const* node = start_container()->next_in_pre_order(); node && node != end_container(); node = node->next_in_pre_order()) { - if (is(*node)) + for (Node const* node = start_container(); node != end_container()->next_sibling(); node = node->next_in_pre_order()) { + if (is(*node) && contains_node(*node)) builder.append(static_cast(*node).data()); } -- cgit v1.2.3