summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-21 19:11:03 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-21 19:14:50 +0100
commit8bc3f4c18611c2190d393fc59f008823f002e579 (patch)
treeb6699fa1a0f17d719daa6e3cbff9cb0dce673c5a /Userland/Libraries/LibWeb/DOM
parent16f4c76da6606f3310a2cb5e5d370672e83fcf62 (diff)
downloadserenity-8bc3f4c18611c2190d393fc59f008823f002e579.zip
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM')
-rw-r--r--Userland/Libraries/LibWeb/DOM/Range.cpp6
1 files changed, 3 insertions, 3 deletions
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<Text>(*start_container()))
- return static_cast<Text const&>(*start_container()).data().substring(start_offset(), end_offset());
+ return static_cast<Text const&>(*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<Text>(*start_container()))
builder.append(static_cast<Text const&>(*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<Text>(*node))
+ for (Node const* node = start_container(); node != end_container()->next_sibling(); node = node->next_in_pre_order()) {
+ if (is<Text>(*node) && contains_node(*node))
builder.append(static_cast<Text const&>(*node).data());
}