Repository navigation
Reject table row and column resizes past the table - #2273
chamber074 wants to merge 1 commit into
Conversation
table.rowHeight and table.columnWidth accepted a row or column the table doesn't have (row 99 on a 2 x 2 table) and reported success. Both now return an invalid-argument error, checked inside the edit before any change, so a refused resize leaves the presentation and the undo and redo history as they were. This is the follow-up storytold#1189's review named. The old test that expected a huge col to be ignored now expects the error.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
AI-generated review (Claude Opus 5.5). Not a maintainer decision.
No blocking problems found.
Both table resize commands now check the row or column index against the table before changing anything, so an index past the end of the table returns an error and leaves the presentation and undo/redo history untouched.
- The check runs inside the table edit (crates/engine/src/cmd/table.rs:640 and :669), so a refused resize changes nothing and adds no undo step; the new test confirms the document is still the same object and the history lengths stay the same.
- The error comes from the same
bad(...)helper as the malformed-index errors and names the command, the key, the index and the table's size (crates/engine/src/cmd/table.rs:631-633). - The drag tool (crates/engine/src/tools/drag.rs:183-185) only passes borders that exist in the table, so dragged resizes are not affected.
- Replacing the old test that expected
col: u64::MAXto succeed is consistent with the issue; the same input is still covered by the rejection test.
Claims checked:
- verified: table.rowHeight and table.columnWidth reject a positive row/col past the end of the table with an invalid-argument error (crates/engine/src/cmd/table.rs:631-633 index_in_table errors when i >= n; called at crates/engine/src/cmd/table.rs:640 with t.n_cols() and crates/engine/src/cmd/table.rs:669 wit…
- verified: A refused resize changes nothing and pushes no history (The check runs inside the with_table closure (crates/engine/src/cmd/table.rs:295 f(t)?) inside edit_shapes/s.edit (crates/engine/src/cmd.rs:485-499), which propagates the error; crates/engine/src/tests.rs test asserts Arc::ptr_eq on the doc an…
- verified: The fallback for an absent row/col and valid resizes (including keepTotal and the drag tool) behave as before (crates/engine/src/cmd/table.rs:266-270 at() unchanged; resize logic at crates/engine/src/cmd/table.rs:643-673 unchanged; crates/engine/src/tools/drag.rs:183-185 passes border indices from…
Reviewed at 4ca6a79.
Recommendation: merge, after a maintainer's decision.
Fixes #2260.
table.rowHeightandtable.columnWidthaccepted positive indices past the end of the table and reported success —row: 99on a 2-row table returned Ok and could commit history. #1189 rejected malformed indices (negative, fractional); its review identified out-of-range positive indices as this follow-up.Changes
crates/engine/src/cmd/table.rs: both resize handlers now check the index against the table's row/column count before mutating, returning the same invalid-argument error shape as the Reject invalid row/col index in table row and column commands #1189 errors (e.g.col 99 is out of range: the table has 2 columns). The check runs inside the edit step, which works on a clone, so a refused resize changes nothing and pushes no history. The fallback for an absentrow/colis unchanged, and valid resizes (includingkeepTotaland the drag tool) behave as before.Tests
table_resize_rejects_a_row_or_column_past_the_table— on a 2 × 2 table with a redo step waiting,row2 and 99,col2 and 99 (with and withoutkeepTotal), andcolu64::MAX each error; the presentation object is untouched, undo/redo lengths are unchanged, and redo afterwards still works.table_resize_in_range_still_works— in-range row and column resizes succeed, one undo step each.table_column_width_of_a_huge_column_is_ignoredasserted thatcol: u64::MAXreturns Ok and changes nothing. That expectation is the behavior Table resize commands report success for a row or column outside the table #2260 reports, so the case now lives in the rejects test above (still no crash, still no change — just an error instead of silent Ok).Fail-before on unmodified main: the rejects test fails at its first case; the in-range test passes.
Verified locally with
cargo xtask ci: every step passes exceptbackstage::tests::start_screen_opens_the_palette_and_preferences(ui-egui), which fails identically on unmodified main in this environment.Drafted with AI assistance; verified and shipped by the contributor.
Summary by CodeRabbit