diff --git a/crates/engine/src/cmd/props.rs b/crates/engine/src/cmd/props.rs index 30a10393..957aeb32 100644 --- a/crates/engine/src/cmd/props.rs +++ b/crates/engine/src/cmd/props.rs @@ -165,7 +165,7 @@ pub(crate) fn letter_spacing(v: &Value) -> Option { fn four(v: &Value) -> Option<[f64; 4]> { match v { Value::Array(a) => { - let f: Vec = a.iter().filter_map(f64_of).collect(); + let f: Vec = a.iter().map(f64_of).collect::>()?; match f.as_slice() { [x] => Some([*x; 4]), [a, b] => Some([*a, *b, *a, *b]), @@ -1291,4 +1291,13 @@ mod tests { } assert!(matches!(line_height(&json!("150%")), Some(LineHeight::Percent(p)) if p == 150.0)); } + + #[test] + fn four_rejects_non_numeric_entries() { + assert_eq!(four(&json!([10, "abc"])), None); + assert_eq!(four(&json!([10, "abc", null, 20])), None); + assert_eq!(four(&json!([10, 20, 30])), None); + assert_eq!(four(&json!([1, 2, 3, 4])), Some([1.0, 2.0, 3.0, 4.0])); + assert_eq!(four(&json!([1, 2])), Some([1.0, 2.0, 1.0, 2.0])); + } }