From da1eb71ad0ba1fb074137eed87a29c25d6bfdd59 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Fri, 13 Feb 2026 14:54:43 +0800 Subject: [PATCH] Add missing validation to Range.comparePoint Also re-order the validation to match what WPT expects. Fixes all cases in dom/ranges/Range-comparePoint.html --- src/browser/webapi/Range.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/browser/webapi/Range.zig b/src/browser/webapi/Range.zig index 85d2ee70..48b72ae9 100644 --- a/src/browser/webapi/Range.zig +++ b/src/browser/webapi/Range.zig @@ -186,10 +186,6 @@ pub fn compareBoundaryPoints(self: *const Range, how_raw: i32, source_range: *co } pub fn comparePoint(self: *const Range, node: *Node, offset: u32) !i16 { - if (offset > node.getLength()) { - return error.IndexSizeError; - } - // Check if node is in a different tree than the range const node_root = node.getRootNode(null); const start_root = self._proto._start_container.getRootNode(null); @@ -197,6 +193,14 @@ pub fn comparePoint(self: *const Range, node: *Node, offset: u32) !i16 { return error.WrongDocument; } + if (node._type == .document_type) { + return error.InvalidNodeType; + } + + if (offset > node.getLength()) { + return error.IndexSizeError; + } + // Compare point with start boundary const cmp_start = AbstractRange.compareBoundaryPoints( node,