Skip to content

Commit a850a90

Browse files
committed
make sure parent is not Document in beforebegin and afterend
1 parent b7ba993 commit a850a90

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/browser/dom/element.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,22 @@ pub const Element = struct {
273273
if (std.mem.eql(u8, position, "beforebegin")) {
274274
// The node must have a parent node in order to use this variant.
275275
const parent = parser.nodeParentNode(self_node) orelse return error.NoModificationAllowed;
276+
// Parent cannot be Document.
277+
// Should have checks for document_fragment and document_type?
278+
if (parser.nodeType(parent) == .document) {
279+
return error.NoModificationAllowed;
280+
}
281+
276282
break :blk .{ parent, self_node };
277283
}
278284

279285
if (std.mem.eql(u8, position, "afterend")) {
280286
// The node must have a parent node in order to use this variant.
281287
const parent = parser.nodeParentNode(self_node) orelse return error.NoModificationAllowed;
288+
// Parent cannot be Document.
289+
if (parser.nodeType(parent) == .document) {
290+
return error.NoModificationAllowed;
291+
}
282292
// Get the next sibling or null; null indicates our node is the only one.
283293
const sibling = parser.nodeNextSibling(self_node);
284294
break :blk .{ parent, sibling };

0 commit comments

Comments
 (0)