Merge PR #1254: Reject invalid index in slide.hide and slide.layout

Conflicts: crates/engine/src/tests.rs (appended both sides' tests)
This commit is contained in:
aiongg committed 2026-10-24 06:16:45 +00:00
commit b7c505a389
2 files changed
+17 -2

No files matched your search

+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
@@ -4581,3 +4581,18 @@ fn format_color_on_a_selected_chart_sets_its_text_color() {
s.execute("format.color", &json!({"color": "accent2"})).unwrap();
assert_eq!(chart_of(&s, id).text_color, Some(deckcraft_model::ColorRef::scheme(deckcraft_color::SchemeSlot::Accent2)));
}
#[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));
}