Truly independent web browser
LibWeb: Stop execCommand when caret canonicalization drops the selection
Andreas Klingbced92b7bdda
diff --git a/Libraries/LibWeb/Editing/ExecCommand.cpp b/Libraries/LibWeb/Editing/ExecCommand.cppindex 6a6e72c1ce4..03ced4ffdb8 100644--- a/Libraries/LibWeb/Editing/ExecCommand.cpp+++ b/Libraries/LibWeb/Editing/ExecCommand.cpp@@ -201,6 +201,12 @@ WebIDL::ExceptionOr<bool> Document::exec_command_internal(Utf16FlyString const&deletion_range->end_container(), deletion_range->end_offset()));}+ // NB: Moving the caret above focuses its editing host, and focusing an editing host such as a contenteditable+ // textarea can remove the selection. Commands with an affected editing host require an active range, so stop+ // here if it is gone.+ if (affected_editing_host && !Editing::active_range(*this))+ return false;+// 5. Take the action for command, passing value to the instructions as an argument.auto command_result = [&] {TemporaryChange running_action { m_running_editing_command_action, true };diff --git a/Tests/LibWeb/Crash/Editing/execCommand-outdent-with-caret-in-textarea-children.html b/Tests/LibWeb/Crash/Editing/execCommand-outdent-with-caret-in-textarea-children.htmlnew file mode 100644index 00000000000..2b96273a114--- /dev/null+++ b/Tests/LibWeb/Crash/Editing/execCommand-outdent-with-caret-in-textarea-children.html@@ -0,0 +1,11 @@+<script>+ const textarea = document.createElement("textarea");+ textarea.contentEditable = "true";+ const list = textarea.appendChild(document.createElement("ol"));+ list.append("q", document.createElement("li"));+ document.documentElement.append(textarea);+ document.designMode = "on";+ getSelection().collapse(list, 1);+ document.designMode = "off";+ document.execCommand("outdent");+</script>