Reject nonpositive MTEXT height on creation (#84) (#154)

This commit is contained in:
MarekSpodBiedry 2026-10-10 18:13:39 +02:00 committed by GitHub
parent bd46065c27
commit 9882b85a41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -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);
}

View File

@ -320,6 +320,9 @@ fn run_mtext(s: &mut Session, p: &Value) -> Result<Value> {
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),