From 1bdd63dabe9718714fb20cc3010b13a559274bfb Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Thu, 29 Oct 2026 11:27:56 +0100 Subject: [PATCH] Reject invalid slide index in animation.clear Found while testing crates/engine/src/cmd/animation.rs:342 (clear) Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Sonnet 5.5 --- crates/engine/src/cmd/animation.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/animation.rs b/crates/engine/src/cmd/animation.rs index ac8348f2..b5d00bba 100644 --- a/crates/engine/src/cmd/animation.rs +++ b/crates/engine/src/cmd/animation.rs @@ -339,7 +339,10 @@ fn options(s: &mut Session, p: &Value) -> Result { } fn clear(s: &mut Session, p: &Value) -> Result { - let i = usize_param(p, "index").unwrap_or(s.doc()?.selection.slide); + let i = match opt_usize_param(p, "index", "animation.clear")? { + Some(i) => i, + None => s.doc()?.selection.slide, + }; s.edit(|doc, _| { if let Some(sl) = doc.slides.get_mut(i) { Arc::make_mut(sl).animations.clear(); @@ -434,6 +437,19 @@ mod tests { use super::*; + #[test] + fn clear_rejects_invalid_index() { + let mut s = Session::with_new(); + let r = s.execute("shape.insert", &json!({"preset": "rect", "rect": [10.0, 10.0, 100.0, 100.0]})).unwrap(); + let id = r.get("id").unwrap().as_u64().unwrap(); + s.execute("animation.add", &json!({"effect": "fade", "class": "entrance", "ids": [id]})).unwrap(); + for bad_index in [json!(-1), json!(1.5)] { + assert!(s.execute("animation.clear", &json!({"index": bad_index})).is_err()); + let left = s.execute("animation.get", &json!({})).unwrap(); + assert_eq!(left.as_array().unwrap().len(), 1); + } + } + #[test] fn animation_painter_copies_effects_between_shapes() { let mut s = Session::with_new();