+PASS (didn't crash)
diff --git a/Tests/LibWeb/Text/input/DOM/ChildNode-after-next-sibling.html b/Tests/LibWeb/Text/input/DOM/ChildNode-after-next-sibling.html
new file mode 100644
index 00000000000..10b63d5a508
--- /dev/null
+++ b/Tests/LibWeb/Text/input/DOM/ChildNode-after-next-sibling.html
@@ -0,0 +1,13 @@
+
+
diff --git a/Tests/LibWeb/Text/input/DOM/ChildNode-before-previous-sibling.html b/Tests/LibWeb/Text/input/DOM/ChildNode-before-previous-sibling.html
new file mode 100644
index 00000000000..ca9e02ed24f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/DOM/ChildNode-before-previous-sibling.html
@@ -0,0 +1,13 @@
+
+
diff --git a/Userland/Libraries/LibWeb/DOM/ChildNode.h b/Userland/Libraries/LibWeb/DOM/ChildNode.h
index 441e23d1a45..a8f97ecaf72 100644
--- a/Userland/Libraries/LibWeb/DOM/ChildNode.h
+++ b/Userland/Libraries/LibWeb/DOM/ChildNode.h
@@ -58,7 +58,7 @@ public:
return {};
// 3. Let viableNextSibling be this’s first following sibling not in nodes; otherwise null.
- auto viable_next_sibling = viable_nest_sibling_for_insertion(nodes);
+ auto viable_next_sibling = viable_next_sibling_for_insertion(nodes);
// 4. Let node be the result of converting nodes into a node, given nodes and this’s node document.
auto node_to_insert = TRY(convert_nodes_to_single_node(nodes, node->document()));
@@ -82,7 +82,7 @@ public:
return {};
// 3. Let viableNextSibling be this’s first following sibling not in nodes; otherwise null.
- auto viable_next_sibling = viable_nest_sibling_for_insertion(nodes);
+ auto viable_next_sibling = viable_next_sibling_for_insertion(nodes);
// 4. Let node be the result of converting nodes into a node, given nodes and this’s node document.
auto node_to_insert = TRY(convert_nodes_to_single_node(nodes, node->document()));
@@ -121,47 +121,47 @@ private:
{
auto* node = static_cast
(this);
- while (auto* previous_sibling = node->previous_sibling()) {
+ for (auto* sibling = node->previous_sibling(); sibling; sibling = sibling->previous_sibling()) {
bool contained_in_nodes = false;
for (auto const& node_or_string : nodes) {
if (!node_or_string.template has>())
continue;
- auto node_in_vector = node_or_string.template get>();
- if (node_in_vector.cell() == previous_sibling) {
+ auto const& node_in_vector = node_or_string.template get>();
+ if (node_in_vector.cell() == sibling) {
contained_in_nodes = true;
break;
}
}
if (!contained_in_nodes)
- return previous_sibling;
+ return sibling;
}
return nullptr;
}
- JS::GCPtr viable_nest_sibling_for_insertion(Vector, String>> const& nodes)
+ JS::GCPtr viable_next_sibling_for_insertion(Vector, String>> const& nodes)
{
auto* node = static_cast(this);
- while (auto* next_sibling = node->next_sibling()) {
+ for (auto* sibling = node->next_sibling(); sibling; sibling = sibling->next_sibling()) {
bool contained_in_nodes = false;
for (auto const& node_or_string : nodes) {
if (!node_or_string.template has>())
continue;
- auto& node_in_vector = node_or_string.template get>();
- if (node_in_vector.cell() == next_sibling) {
+ auto const& node_in_vector = node_or_string.template get>();
+ if (node_in_vector.cell() == sibling) {
contained_in_nodes = true;
break;
}
}
if (!contained_in_nodes)
- return next_sibling;
+ return sibling;
}
return nullptr;