Clamp huge index in table.insertRowBelow/insertColumnRight

Found while testing crates/engine/src/cmd/table.rs:291

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-16 04:09:45 +00:00
co-authored by Claude Haiku 5.5
parent f4731822c9
commit 1bb408462c
2 changed files with 18 additions and 2 deletions
+2 -2
View File
@@ -288,9 +288,9 @@ fn rows_cols(s: &mut Session, p: &Value, op: &str) -> Result<Value> {
with_table(s, p, "table", move |t| {
match op.as_str() {
"rowAbove" => t.insert_row(r),
"rowBelow" => t.insert_row(r + 1),
"rowBelow" => t.insert_row(r.saturating_add(1)),
"colLeft" => t.insert_col(c),
"colRight" => t.insert_col(c + 1),
"colRight" => t.insert_col(c.saturating_add(1)),
"delRow" => {
if !t.delete_row(r) {
return Err(bad("table.deleteRow", "can't delete the last row"));
+16
View File
@@ -3576,3 +3576,19 @@ fn shape_ids_beyond_u32_are_rejected_not_wrapped() {
assert!(s.execute("shape.sites", &json!({"id": a.0})).is_ok());
assert!(s.execute("shape.connect", &json!({"from": a.0, "to": b.0})).is_ok());
}
#[test]
fn table_insert_below_or_right_of_a_huge_index_appends_at_the_end() {
let mut s = session();
let id = table_at(&mut s, &[100.0, 100.0], json!([["a", "b"], ["c", "d"]]));
let r = s.execute("table.insertRowBelow", &json!({"id": id.0, "row": u64::MAX}));
assert!(r.is_ok(), "insertRowBelow must clamp a huge row, got {r:?}");
let t = table_of(&s, id);
assert_eq!(t.n_rows(), 3);
assert_eq!(t.cell(0, 0).unwrap().text.text(), "a", "the original rows keep their place");
let r = s.execute("table.insertColumnRight", &json!({"id": id.0, "col": u64::MAX}));
assert!(r.is_ok(), "insertColumnRight must clamp a huge col, got {r:?}");
let t = table_of(&s, id);
assert_eq!(t.n_cols(), 3);
assert_eq!(t.cell(0, 1).unwrap().text.text(), "b", "the original columns keep their place");
}