Commands: path.create with path data refuses closed given as text, and the grids refuse a count

path.create read closed only when it drew from anchors. Given path
data, {"d": "M0 0 L10 0 L10 10", "closed": "true"} drew the path and
recorded an undo step, while the same closed with anchors fails with
"`closed` must be true or false". shape.rectangularGrid and
shape.polarGrid read rows, columns, concentric and radial given as text
as the count left out, so {"rows": "3"} drew the default 5 horizontal
dividers instead of 3.

path.create now checks closed before it reads d or anchors, and the
grid commands refuse such a count with "`rows` must be a number, not
"3"". Neither command changes the document or its undo history then.
With d, a closed of true, false or null still leaves the path as its
path data draws it.

Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo
2026-10-22 08:24:09 +07:00
committed by bflatastic
parent aef00190ed
commit bfc3f5251a
5 changed files with 34 additions and 8 deletions
+17
View File
@@ -1257,6 +1257,23 @@ fn shape_commands_refuse_a_number_or_boolean_given_as_text() {
s.execute("shape.arc", &json!({"x1": 0, "y1": 0, "x2": 50, "y2": 50, "closed": false})).unwrap();
}
/// `path.create` given path data (`d`) refuses a `closed` other than true, false or null, as it does
/// with `anchors`, and draws nothing; with true, false or null it draws the path data, which alone
/// decides whether the path is closed.
#[test]
fn path_create_with_path_data_refuses_closed_given_as_text() {
let mut s = session();
let d = "M0 0 L10 0 L10 10";
let calls = [json!("true"), json!(1), json!([true])].map(|v| not_a_switch("path.create", json!({"d": d, "closed": v}), "closed"));
let wrong = not_refused(&mut s, &calls);
assert!(wrong.is_empty(), "not refused: {wrong:#?}");
for closed in [json!(true), json!(false), json!(null)] {
let id = NodeId(s.execute("path.create", &json!({"d": d, "closed": closed})).unwrap()["id"].as_u64().unwrap());
let NodeKind::Path { path, .. } = &s.doc().unwrap().doc.node(id).unwrap().kind else { panic!("a path") };
assert_eq!((path.subpaths.len(), path.anchor_count(), path.is_closed()), (1, 3, false), "closed: {closed}");
}
}
/// #1824: with anchors selected with Direct Selection, the Transform panel's X/Y/W/H
/// (`object.setBounds`) are the box around those anchors, and only they move or scale.
#[test]