diff --git a/crates/engine/src/cmd/annotate_tests.rs b/crates/engine/src/cmd/annotate_tests.rs index 267510df7..b9985821d 100644 --- a/crates/engine/src/cmd/annotate_tests.rs +++ b/crates/engine/src/cmd/annotate_tests.rs @@ -341,3 +341,14 @@ fn hostile_annotation_params_never_panic() { let _ = cadcraft_render::build(s.doc().unwrap(), &cadcraft_doc::Space::Model, &cadcraft_render::Options::default()); assert!(matches!(dim(&s, d).kind, DimKind::Linear { .. })); } + +#[test] +fn mtext_rejects_nonpositive_height() { + let mut s = Session::new(); + for height in [0.0, -2.0] { + assert!(s.execute("mtext", &json!({ "at": [0, 0], "text": "hi", "height": height })).is_err(), "height {height}"); + } + assert!(s.doc().unwrap().model.is_empty()); + s.execute("mtext", &json!({ "at": [0, 0], "text": "hi", "height": 2 })).unwrap(); + assert_eq!(s.doc().unwrap().model.len(), 1); +} diff --git a/crates/engine/src/cmd/draw.rs b/crates/engine/src/cmd/draw.rs index 9b90f8c35..188ea9edb 100644 --- a/crates/engine/src/cmd/draw.rs +++ b/crates/engine/src/cmd/draw.rs @@ -320,6 +320,9 @@ fn run_mtext(s: &mut Session, p: &Value) -> Result { let at = point_req("mtext", p, "at")?; let text = str_param(p, "text").ok_or_else(|| bad("mtext", "`text` is required"))?; let height = f64_or(p, "height", s.doc()?.header.f64("TEXTSIZE", 0.2)); + if height <= 0.0 { + return Err(bad("mtext", "height must be positive")); + } let style = s.doc()?.header.str("TEXTSTYLE", "Standard"); let k = EntityKind::MText(MText { insert: v3(at),