From 495243c5b6d78936d984f517b060262efa5bd519 Mon Sep 17 00:00:00 2001 From: Marco Arnulfo Date: Thu, 29 Oct 2026 22:39:28 +0100 Subject: [PATCH] Scale Composition: refuse more than one of factor, width and height instead of ignoring the others --- crates/engine/src/cmd/comp_more.rs | 4 ++++ crates/engine/src/tests/scale_comp.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/crates/engine/src/cmd/comp_more.rs b/crates/engine/src/cmd/comp_more.rs index 940c09f8d..6eaeda862 100644 --- a/crates/engine/src/cmd/comp_more.rs +++ b/crates/engine/src/cmd/comp_more.rs @@ -153,6 +153,10 @@ fn scale_comp(s: &mut Session, p: &Value) -> Result { let cid = comp_id(s, p)?; let comp = s.project.comp(cid).ok_or(EngineError::NoComp)?; let (ow, oh) = (f64::from(comp.width), f64::from(comp.height)); + // The three are alternatives: with two, one would be ignored without a word. + if ["factor", "width", "height"].iter().filter(|k| f_p(p, k).is_some()).count() > 1 { + return Err(bad(C, "pass only one of `factor`, `width` or `height`")); + } let f = match (f_p(p, "factor"), f_p(p, "width"), f_p(p, "height")) { (Some(f), ..) => f, (None, Some(w), _) => w / ow, diff --git a/crates/engine/src/tests/scale_comp.rs b/crates/engine/src/tests/scale_comp.rs index aad1511d9..752ce9fe5 100644 --- a/crates/engine/src/tests/scale_comp.rs +++ b/crates/engine/src/tests/scale_comp.rs @@ -273,6 +273,8 @@ fn scale_comp_refuses_a_bad_factor_and_changes_nothing() { (json!({"width": 0}), "4 to 30,000 px"), (json!({"factor": 100}), "4 to 30,000 px"), (json!({"factor": 0.001}), "4 to 30,000 px"), + (json!({"factor": 2, "width": 960}), "only one of"), + (json!({"width": 960, "height": 360}), "only one of"), ]; for (p, why) in cases { match s.execute("comp.scale", p.clone()) {