Merge pull request #1467 from Silvertree2010/fix/h3521-node-set-paddinghorizontal-paddi

Reject non-numeric paddingHorizontal/paddingVertical in node.set
This commit is contained in:
BFlat
2026-10-29 11:38:41 +07:00
committed by GitHub
2 changed files with 15 additions and 2 deletions
+13
View File
@@ -181,6 +181,19 @@ mod tests {
assert!(s.execute("node.set", &json!({"id": f, "props": {"paddingLeft": "wide"}})).is_err());
}
#[test]
fn junk_axis_padding_is_refused_and_keeps_padding() {
let mut s = Session::new();
let (f, _, _) = al_frame(&mut s);
ex(&mut s, "node.set", json!({"id": f, "props": {"padding": 16}}));
for key in ["paddingHorizontal", "paddingVertical"] {
for junk in [json!("abc"), json!({"a": 1}), json!([1, 2])] {
assert!(s.execute("node.set", &json!({"id": f, "props": {key: junk}})).is_err(), "{key}");
assert_eq!(node(&s, f).layout.as_ref().unwrap().padding, [16.0; 4], "{key}");
}
}
}
#[test]
fn baseline_alignment_lines_up_text() {
let mut s = Session::new();
+2 -2
View File
@@ -650,13 +650,13 @@ fn apply_layout(cmd: &str, doc: &mut Document, id: NodeId, k: &str, v: &Value) -
}
}
"paddingHorizontal" => {
let val = f64_of(v).unwrap_or(0.0).max(0.0);
let val = f64_of(v).ok_or_else(|| bad(cmd, format!("`{k}` must be a number")))?.max(0.0);
let l = layout_mut(cmd, k, doc.get_mut(id)?)?;
l.padding[1] = val;
l.padding[3] = val;
}
"paddingVertical" => {
let val = f64_of(v).unwrap_or(0.0).max(0.0);
let val = f64_of(v).ok_or_else(|| bad(cmd, format!("`{k}` must be a number")))?.max(0.0);
let l = layout_mut(cmd, k, doc.get_mut(id)?)?;
l.padding[0] = val;
l.padding[2] = val;