Reject cornerRadius/padding/strokeSides arrays with non-numeric entries

Found while testing crates/engine/src/cmd/props.rs:165-175 (four, used at :506, :540 and :613)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-27 03:21:33 +00:00
co-authored by Claude Haiku 5.5
parent 43af145a12
commit aeaca0e1b9
+10 -1
View File
@@ -165,7 +165,7 @@ pub(crate) fn letter_spacing(v: &Value) -> Option<LetterSpacing> {
fn four(v: &Value) -> Option<[f64; 4]> {
match v {
Value::Array(a) => {
let f: Vec<f64> = a.iter().filter_map(f64_of).collect();
let f: Vec<f64> = a.iter().map(f64_of).collect::<Option<_>>()?;
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]));
}
}