Merge pull request #866 from Silvertree2010/fix/h1968-table-insertrowbelow-insertcolum

Clamp huge index in table.insertRowBelow/insertColumnRight
This commit is contained in:
skylar taylor-barrick
2026-10-15 23:13:10 -06:00
committed by GitHub
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| { with_table(s, p, "table", move |t| {
match op.as_str() { match op.as_str() {
"rowAbove" => t.insert_row(r), "rowAbove" => t.insert_row(r),
"rowBelow" => t.insert_row(r + 1), "rowBelow" => t.insert_row(r.saturating_add(1)),
"colLeft" => t.insert_col(c), "colLeft" => t.insert_col(c),
"colRight" => t.insert_col(c + 1), "colRight" => t.insert_col(c.saturating_add(1)),
"delRow" => { "delRow" => {
if !t.delete_row(r) { if !t.delete_row(r) {
return Err(bad("table.deleteRow", "can't delete the last row")); 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.sites", &json!({"id": a.0})).is_ok());
assert!(s.execute("shape.connect", &json!({"from": a.0, "to": b.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");
}