From 1870f1a0a8f21b8825491c35ed0e82c7cf584a3f Mon Sep 17 00:00:00 2001 From: Nathan van der Kamp Date: Sun, 24 Nov 2024 23:40:07 +0100 Subject: [PATCH] LibWeb: Fix crash when skipping to previous word with ctrl+left arrow Before this change, skipping a word to the left in a non empty text input element would crash when near the end of the text as the offset + length of the substring would exceed the length of the string. --- Libraries/LibWeb/HTML/FormAssociatedElement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp index a01eb99dd49..568dd09277c 100644 --- a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp +++ b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp @@ -794,7 +794,7 @@ void FormAssociatedTextControlElement::decrement_cursor_position_to_previous_wor while (true) { if (auto offset = text_node->word_segmenter().previous_boundary(m_selection_end); offset.has_value()) { - auto word = text_node->data().code_points().substring_view(m_selection_end, m_selection_end - *offset); + auto word = text_node->data().code_points().substring_view(*offset, m_selection_end - *offset); if (collapse == CollapseSelection::Yes) { collapse_selection_to_offset(*offset); } else {