Reject invalid index in slide.hide and slide.layout

Found while testing crates/engine/src/cmd/slide.rs:376 (hide); same pattern at slide.rs:445

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-24 02:16:19 +00:00
co-authored by Claude Haiku 5.5
parent 9aef21e627
commit 6d7b32351f
2 changed files with 17 additions and 2 deletions
+2 -2
View File
@@ -373,7 +373,7 @@ fn select_slides(s: &mut Session, p: &Value) -> Result<Value> {
}
fn hide(s: &mut Session, p: &Value) -> Result<Value> {
let targets: Vec<usize> = match usize_param(p, "index") {
let targets: Vec<usize> = match opt_usize_param(p, "index", "slide.hide")? {
Some(i) => vec![i],
None => {
let st = s.doc()?;
@@ -442,7 +442,7 @@ pub fn apply_layout(doc: &mut Presentation, index: usize, layout: LayoutId) -> R
fn set_layout(s: &mut Session, p: &Value) -> Result<Value> {
let key = p.get("layout").cloned().ok_or_else(|| bad("slide.layout", "missing `layout`"))?;
let targets: Vec<usize> = match usize_param(p, "index") {
let targets: Vec<usize> = match opt_usize_param(p, "index", "slide.layout")? {
Some(i) => vec![i],
None => {
let st = s.doc()?;
+15
View File
@@ -4403,3 +4403,18 @@ fn duplicating_a_moved_copy_repeats_the_move() {
assert_eq!(boxed(&mut s, f), (340.0 + off, 100.0 + off));
assert_eq!(s.doc().unwrap().doc.validate(), Vec::<String>::new());
}
#[test]
fn slide_hide_and_layout_reject_invalid_index() {
let mut s = session();
s.execute("slide.new", &json!({})).unwrap();
s.execute("slide.new", &json!({})).unwrap();
s.execute("slide.selectSlides", &json!({"indices": [0]})).unwrap();
for bad in [json!(-1), json!(1.5)] {
let e = s.execute("slide.hide", &json!({"index": bad})).unwrap_err().to_string();
assert!(e.contains("not a valid index"), "{e}");
let e = s.execute("slide.layout", &json!({"layout": "blank", "index": bad})).unwrap_err().to_string();
assert!(e.contains("not a valid index"), "{e}");
}
assert!(s.doc().unwrap().doc.slides.iter().all(|x| !x.hidden));
}