mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
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
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:
@@ -37,6 +37,10 @@ pub fn init(page: *Page) !*Range {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn setStart(self: *Range, node: *Node, offset: u32) !void {
|
pub fn setStart(self: *Range, node: *Node, offset: u32) !void {
|
||||||
|
if (node._type == .document_type) {
|
||||||
|
return error.InvalidNodeType;
|
||||||
|
}
|
||||||
|
|
||||||
if (offset > node.getLength()) {
|
if (offset > node.getLength()) {
|
||||||
return error.IndexSizeError;
|
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 {
|
pub fn setEnd(self: *Range, node: *Node, offset: u32) !void {
|
||||||
|
if (node._type == .document_type) {
|
||||||
|
return error.InvalidNodeType;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate offset
|
// Validate offset
|
||||||
if (offset > node.getLength()) {
|
if (offset > node.getLength()) {
|
||||||
return error.IndexSizeError;
|
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 {
|
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
|
// Check if node is in a different tree than the range
|
||||||
const node_root = node.getRootNode(null);
|
const node_root = node.getRootNode(null);
|
||||||
const start_root = self._proto._start_container.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;
|
return error.WrongDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node._type == .document_type) {
|
||||||
|
return error.InvalidNodeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset > node.getLength()) {
|
||||||
|
return error.IndexSizeError;
|
||||||
|
}
|
||||||
|
|
||||||
// Compare point with start boundary
|
// Compare point with start boundary
|
||||||
const cmp_start = AbstractRange.compareBoundaryPoints(
|
const cmp_start = AbstractRange.compareBoundaryPoints(
|
||||||
node,
|
node,
|
||||||
|
|||||||
Reference in New Issue
Block a user