summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-07-14 09:11:34 -0400
committerAndreas Kling <kling@serenityos.org>2021-07-14 17:16:39 +0200
commitf7acd6aca52f16076232d3a95eccbe3f896252cb (patch)
treec00558342959d890a806ee0c830f8d5b670d019b
parent22ab512f39f02338bfbb6b2260eb21eed3a5eaf3 (diff)
downloadserenity-f7acd6aca52f16076232d3a95eccbe3f896252cb.zip
LibWeb: Handle when the last selected node does not contain text
If the text-for-rendering of the last selected node is empty, the select all implementation would end up setting the index to -1. This value is used directly for a substring length in the copy text implementation, thus would cause a failed assertion.
-rw-r--r--Userland/Libraries/LibWeb/Page/BrowsingContext.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp
index 70d9beeb4b..58698078f1 100644
--- a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp
+++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp
@@ -305,8 +305,11 @@ void BrowsingContext::select_all()
VERIFY(last_layout_node);
int last_layout_node_index_in_node = 0;
- if (is<Layout::TextNode>(*last_layout_node))
- last_layout_node_index_in_node = verify_cast<Layout::TextNode>(*last_layout_node).text_for_rendering().length() - 1;
+ if (is<Layout::TextNode>(*last_layout_node)) {
+ auto const& text_for_rendering = verify_cast<Layout::TextNode>(*last_layout_node).text_for_rendering();
+ if (!text_for_rendering.is_empty())
+ last_layout_node_index_in_node = text_for_rendering.length() - 1;
+ }
layout_root->set_selection({ { first_layout_node, 0 }, { last_layout_node, last_layout_node_index_in_node } });
}