Merge pull request #1539 from lightpanda-io/range_set_validation
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
e2e-integration-test / zig build release (push) Has been cancelled
e2e-integration-test / demo-integration-scripts (push) Has been cancelled

Add missing validation to range setStart and setEnd
This commit is contained in:
Karl Seguin
2026-02-14 07:03:27 +08:00
committed by GitHub

View File

@@ -37,6 +37,10 @@ pub fn init(page: *Page) !*Range {
}
pub fn setStart(self: *Range, node: *Node, offset: u32) !void {
if (node._type == .document_type) {
return error.InvalidNodeType;
}
if (offset > node.getLength()) {
return error.IndexSizeError;
}
@@ -54,6 +58,10 @@ pub fn setStart(self: *Range, node: *Node, offset: u32) !void {
}
pub fn setEnd(self: *Range, node: *Node, offset: u32) !void {
if (node._type == .document_type) {
return error.InvalidNodeType;
}
// Validate offset
if (offset > node.getLength()) {
return error.IndexSizeError;
@@ -178,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);
@@ -189,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,