Repository navigation
Reject a loaded state with no current item but items, or any invalid state from a custom provider [patch] - #86
Merged
Conversation
…state from a custom provider [patch] NavigationState accepted currentIndex -1 alongside items, and LoadStateAsync trusted whatever INavigationState a provider returned. A stack loaded that way had items but no current page, so the next NavigateTo treated them all as forward history and deleted them, and the corrupt state then saved again. NavigationState now rejects -1 when there are items, and LoadStateAsync checks every loaded state itself (no null items, the index names an item, -1 only when empty), returning false and leaving the stack unchanged when it is invalid. Fixes #69 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012PhWKjgHTCiWEe29MuG6G3
|
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 #69
What was wrong
NavigationState<T>acceptedcurrentIndex: -1alongside a non-emptyitems.Navigation<T>.LoadStateAsyncpassed whateverINavigationState<T>the provider returned straight to the stack. A custom provider's own state type skipped even the null-item and range checks inNavigationState's constructor.After such a load the stack had items but no current page. The next
NavigateTotreated every restored item as forward history and deleted it, andSaveStateAsyncthen saved the corrupt state again.The change
The
NavigationState<T>constructor now throwsArgumentOutOfRangeExceptionfor-1when there are items.JsonFilePersistenceProvideralready turns anArgumentExceptioninto anullload.LoadStateAsynccopies the loaded items once and checks them itself, whichever provider they came from:-1 <= CurrentIndex < Items.Count-1only when there are no itemsIf the state is invalid (including a null
Items), it returnsfalseand the stack, its undo history and its events are untouched.Tests
The new file
Navigation.Test/LoadedStateValidationTests.cscovers:-1with items, and accepting it with nonecurrentIndex: -1with two items), which loads asfalseand leaves the existing stack alonefalsewith the stack unchangedWith the source changes reverted, 6 of the 8 new tests fail; the two that pass are the valid-state cases. With the change, all 54 tests pass.
🤖 Generated with Claude Code
https://claude.ai/code/session_012PhWKjgHTCiWEe29MuG6G3
Generated by Claude Code