Reject malformed saved state without losing the live history - #87
Merged
Merged
Conversation
…tch] LoadStateAsync let NullReferenceException and ArgumentNullException escape on valid JSON with missing or null fields, and RestoreFromState cleared the stack before validating, so a bad file could wipe the in-memory history. The JSON serializer now validates the shape and throws InvalidOperationException, and RestoreFromState checks commands, save boundaries and position before clearing anything. Fixes #81 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016ToeUpj3nH61YEnatKdb8d
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #81
What was wrong
LoadStateAsyncletNullReferenceExceptionandArgumentNullExceptionescape on JSON that parses but has missing or null fields. Its contract is to returnfalsefor data it cannot load.RestoreFromStatecleared the stack and save boundaries before validating the state. A failed load could wipe the user's in-memory history.Change
JsonUndoRedoSerializer.DeserializeAsync:formatVersionas unsupported.ValidateShapethrowsInvalidOperationException, whichLoadStateAsyncalready catches, for any of: nullcommands, nullsaveBoundaries, a null entry in either list, or a command with nometadata.UndoRedoService.RestoreFromStatechecks all of the following before clearing anything, and returnsfalsewith the current history untouched if any check fails:CommandsandSaveBoundariesare non-null and contain no null entries.CurrentPositionis in[-1, Commands.Count - 1].Tests
UndoRedoService_LoadStateMalformed_ReturnsFalseAndKeepsHistoryhas six data rows: the four payloads from the issue, plus a null save-boundary entry and a null format version. Each row assertsfalseand that commands, position and boundaries are unchanged.UndoRedoService_RestoreFromStateInvalidPosition_ReturnsFalseAndKeepsHistorycovers positions 2 and -2.UndoRedoService_RestoreFromStateNullSaveBoundaries_ReturnsFalseAndKeepsHistorycallsRestoreFromStatedirectly with a null boundaries list.Verification
🤖 Generated with Claude Code
https://claude.ai/code/session_016ToeUpj3nH61YEnatKdb8d
Generated by Claude Code