Skip to content

Transform commands: a string for an optional number is an error (#1952) - #1967

Merged
bflatastic merged 1 commit into
storytold:mainfrom
switch87:fix/1952-optional-number-strings
Oct 15, 2026
Merged

bflatastic merged 1 commit into
storytold:mainfrom
switch87:fix/1952-optional-number-strings

Conversation

@switch87

Copy link
Copy Markdown
Contributor

Fixes #1952

object.setBounds read x, y, width and height with f64_or, which falls back to the current value for anything that isn't a JSON number. {"width": "60 mm"} therefore returned {"ids": [...]}, exited 0 and changed nothing. The other Transform commands did the same with their optional numbers: object.move (dx, dy), object.nudge (dx, dy), object.rotate (angle), object.scale (sy) and object.shear (angle).

A value that is neither a number nor null is now a BadParams error that names the key (for example object.setBounds: `width` must be a number, not "60 mm"), as a missing required number already is. Numbers and null behave as before. Unit strings are not parsed: the parameters stay in points.

The check is a small helper, check_numbers in cmd/mod.rs, called at the top of each command, so nothing changes in the document or the undo history before the error. #1964 (audit) sketches the same check for object.setBounds only. This PR also covers the sibling transform commands.

Behaviour change: scripts that passed a string or other non-number to these optional parameters used to succeed silently with the value ignored. They now get an error.

Tests

  • a_string_for_an_optional_transform_number_is_an_error (crates/engine/src/tests.rs): every command above, given a string, bool or array, returns BadParams naming the key and leaves the bounds and undo history unchanged; width: 60 with height: null still works. It fails on main, where object.setBounds {"width": "60 mm"} returns Ok.
  • cargo xtask ci: fmt, clippy, test (6575 passed, 0 failed), assets, brands and layers pass. I could not run the wasm step locally because the Gentoo Rust toolchain here has no wasm32 std (can't find crate for std), so CI has to check it.

@Messhias Messhias left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix for the silent ignore of stringy optional numbers. check_numbers is clear, covers the Transform panel commands, and the regression test checks both BadParams and that history/bounds stay put.

…ytold#1952)

object.setBounds read x, y, width and height with f64_or, which falls back
to the current value for anything that isn't a JSON number, so
{"width": "60 mm"} returned ok and changed nothing. object.move,
object.nudge, object.rotate, object.scale (sy) and object.shear did the
same with their optional numbers. A value that is neither a number nor
null is now a BadParams error naming the key, as a missing required
number already is.
@bflatastic
bflatastic force-pushed the fix/1952-optional-number-strings branch from 136f28e to e6170de Compare October 15, 2026 20:20
@bflatastic
bflatastic merged commit a324b0e into storytold:main Oct 15, 2026
1 check passed
@bflatastic

Copy link
Copy Markdown
Member

Thanks @switch87! Merged after a full gate. Checked over MCP: object.move {dx: "5"} is refused with your message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A string for an optional number parameter is silently ignored ("60 mm")

3 participants