Truly independent web browser
LibWeb: Stop the delete command from climbing up to the Document
Andreas Kling2f179757f854
diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cppindex 3825ec9fae6..cdff48f67a0 100644--- a/Libraries/LibWeb/Editing/Commands.cpp+++ b/Libraries/LibWeb/Editing/Commands.cpp@@ -310,9 +310,10 @@ bool command_delete_action(DOM::Document& document, Utf16View)// 9. Repeat the following steps:while (true) {- // AD-HOC: If start node is not a Node, return false. This prevents a crash by dereferencing a null pointer in- // step 1 below. Edits outside of <body> might be prohibited: https://github.com/w3c/editing/issues/405- if (!start_node)+ // AD-HOC: If start node is not a Node or is a Document, return false. This prevents a crash by dereferencing a+ // null pointer in step 1 below, and by collapsing the selection into a doctype in step 17. Edits+ // outside of <body> might be prohibited: https://github.com/w3c/editing/issues/405+ if (!start_node || start_node->is_document())return false;// 1. If start offset is zero, set start offset to the index of start node and then setdiff --git a/Tests/LibWeb/Crash/Editing/execCommand-delete-at-start-of-document-element.html b/Tests/LibWeb/Crash/Editing/execCommand-delete-at-start-of-document-element.htmlnew file mode 100644index 00000000000..eff650408fd--- /dev/null+++ b/Tests/LibWeb/Crash/Editing/execCommand-delete-at-start-of-document-element.html@@ -0,0 +1,6 @@+<!DOCTYPE html>+<script>+ document.designMode = "on";+ getSelection().collapse(document.documentElement, 0);+ document.execCommand("delete");+</script>