Skip to content

Truly independent web browser

LibWeb: Collect outdent's preceding siblings in tree order

Andreas Klingec7ee9d08341
diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
index ba019acd66f..b4b1bf58a2a 100644
--- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
+++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp
@@ -3294,8 +3294,10 @@ void outdent(GC::Ref<DOM::Node> node)
// 5. Let preceding siblings be the precedings siblings of target, and let following siblings be the followings
// siblings of target.
+ // NB: Both lists are in tree order, like in the spec's reference implementation. Indenting a list relies on
+ // this, since it looks for a new parent next to the first and last members of the list.
Vector<GC::Ref<DOM::Node>> preceding_siblings;
- for (auto* sibling = target->previous_sibling(); sibling; sibling = sibling->previous_sibling())
+ for (auto* sibling = current_ancestor->first_child(); sibling != target.ptr(); sibling = sibling->next_sibling())
preceding_siblings.append(*sibling);
Vector<GC::Ref<DOM::Node>> following_siblings;
for (auto* sibling = target->next_sibling(); sibling; sibling = sibling->next_sibling())
diff --git a/Tests/LibWeb/Crash/Editing/execCommand-outdent-with-indented-preceding-sibling.html b/Tests/LibWeb/Crash/Editing/execCommand-outdent-with-indented-preceding-sibling.html
new file mode 100644
index 00000000000..6c8e1496d77
--- /dev/null
+++ b/Tests/LibWeb/Crash/Editing/execCommand-outdent-with-indented-preceding-sibling.html
@@ -0,0 +1,6 @@
+<div id="editor" contenteditable><blockquote><blockquote>x</blockquote><br><div id="target">b</div></blockquote></div>
+<script>
+ editor.focus();
+ getSelection().collapse(target.firstChild, 0);
+ document.execCommand("outdent");
+</script>
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/run/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/editing/run/[email protected]
index d28d2daf09f..aa13eeaf352 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/run/[email protected]
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/run/[email protected]
@@ -2,8 +2,8 @@ Harness status: OK
Found 550 tests
-548 Pass
-2 Fail
+549 Pass
+1 Fail
Pass [["outdent",""]] "<blockquote>foo<ol><li>[bar]</ol>baz</blockquote><p>extra" queryCommandIndeterm("outdent") after
Pass [["outdent",""]] "<blockquote>foo<ol><li>[bar]</ol>baz</blockquote><p>extra" queryCommandState("outdent") after
Pass [["outdent",""]] "<blockquote>foo<ol><li>[bar]</ol>baz</blockquote><p>extra" queryCommandValue("outdent") after
@@ -305,7 +305,7 @@ Pass [["outdent",""]] "<blockquote> <p>foo</p> <p>[bar]</p> <p>baz</p></blockquo
Pass [["outdent",""]] "<blockquote> <p>foo</p> <p>[bar]</p> <p>baz</p></blockquote>" queryCommandValue("outdent") after
Pass [["outdent",""]] "<blockquote> <p>foo</p> <p>bar</p> <p>[baz]</p></blockquote>": execCommand("outdent", false, "") return value
Pass [["outdent",""]] "<blockquote> <p>foo</p> <p>bar</p> <p>[baz]</p></blockquote>" checks for modifications to non-editable content
-Fail [["outdent",""]] "<blockquote> <p>foo</p> <p>bar</p> <p>[baz]</p></blockquote>" compare innerHTML
+Pass [["outdent",""]] "<blockquote> <p>foo</p> <p>bar</p> <p>[baz]</p></blockquote>" compare innerHTML
Pass [["outdent",""]] "<blockquote> <p>foo</p> <p>bar</p> <p>[baz]</p></blockquote>" queryCommandIndeterm("outdent") before
Pass [["outdent",""]] "<blockquote> <p>foo</p> <p>bar</p> <p>[baz]</p></blockquote>" queryCommandState("outdent") before
Pass [["outdent",""]] "<blockquote> <p>foo</p> <p>bar</p> <p>[baz]</p></blockquote>" queryCommandValue("outdent") before