Skip to content

Reject saved state with save boundaries outside the commands - #97

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/undoredo-90-validate-boundary-positions
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/undoredo-90-validate-boundary-positions

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #90

What changed

IsRestorable (added in #81) rejected null save boundaries but never checked their positions. A corrupt or hand-edited state with boundaries at -7 or 42 therefore loaded, and the phantom save points ended up in SaveBoundaries and the unsaved-changes logic.

It now also requires every boundary to satisfy -1 <= Position < Commands.Count. RestoreFromState and LoadStateAsync return false for such a state and leave the live history as it was.

Tests

  • UndoRedoService_RestoreFromStateInvalidBoundaryPosition_ReturnsFalseAndKeepsHistory covers -7, -2, the command count, and 42.
  • UndoRedoService_LoadStateAsyncInvalidBoundaryPosition_ReturnsFalseAndKeepsHistory runs the same case through the JSON serializer.
  • UndoRedoService_RestoreFromStateBoundaryAtEdge_Restores checks that the valid edges, -1 and the last command, are still accepted.

I reverted the one-line fix and the five rejection cases failed. With the fix, the full suite passes (76/76).

Note: the #88 triage proposes the same boundary-range check, so this PR covers that part of #88.

🤖 Generated with Claude Code

https://claude.ai/code/session_01N4m2HJkrsY88XBtTqTKAkE


Generated by Claude Code

…tch]

IsRestorable checked that save boundaries were non-null but never checked
their positions, so a corrupt state with boundaries at -7 or 42 loaded and
left phantom save points behind. Require every boundary to sit between -1
and the last command, so RestoreFromState and LoadStateAsync reject the
state and keep the live history.

Fixes #90

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01N4m2HJkrsY88XBtTqTKAkE
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 570250a into main Sep 27, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/undoredo-90-validate-boundary-positions branch September 27, 2026 00:18
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.

RestoreFromState/LoadStateAsync accept save boundaries at impossible positions (e.g. -7 or 42 with zero commands)

2 participants