Reject negative and fractional indexes in node.reorder

Found while testing crates/engine/src/cmd/edit.rs:329

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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-11-03 01:41:31 +01:00
co-authored by Claude Haiku 5.5
parent 02c38a6d95
commit 41ec33eeec
2 changed files with 14 additions and 1 deletions
+13
View File
@@ -345,3 +345,16 @@ fn remove_all_auto_layout_strips_the_frame_and_every_frame_nested_in_it() {
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(laid_out(&s), [true, true, true]);
}
#[test]
fn reorder_rejects_negative_and_fractional_indexes() {
let mut s = Session::new();
let f = frame(&mut s, None, 0.0, 0.0, 200.0, 200.0);
let a = rect(&mut s, Some(f), 0.0, 0.0, 10.0, 10.0);
let b = rect(&mut s, Some(f), 0.0, 0.0, 10.0, 10.0);
let c = rect(&mut s, Some(f), 0.0, 0.0, 10.0, 10.0);
for bad in [json!(-1), json!(0.5), json!("x")] {
assert!(s.execute("node.reorder", &json!({"id": c, "index": bad})).is_err(), "{bad} accepted");
assert_eq!(kids(&s, f), vec![a, b, c]);
}
}
+1 -1
View File
@@ -326,7 +326,7 @@ pub fn specs() -> Vec<CommandSpec> {
),
spec!("node.reorder", "Reorder layer", "{id, index}", true, |s, p| {
let i = req_id("node.reorder", p, "id")?;
let idx = req_num("node.reorder", p, "index")?.max(0.0) as usize;
let idx = req_index("node.reorder", p, "index")?;
s.doc_mut()?.reorder(i, idx)?;
ok()
}),