Validate RichTextViewModel search match rangesFix/rich text search stale ranges#372
Open
robfeldmann wants to merge 2 commits into
Open
Validate RichTextViewModel search match rangesFix/rich text search stale ranges#372robfeldmann wants to merge 2 commits into
RichTextViewModel search match rangesFix/rich text search stale ranges#372robfeldmann wants to merge 2 commits into
Conversation
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.
Summary
Fixes a crash in
RichTextViewModelwhen search match ranges computed fromoriginalTextare later applied to a changedNSTextStorage.Crash stack trace...
The crash happens when stale
NSRangevalues are passed intoNSTextStorage/NSMutableAttributedStringAPIs, which can throw anNSRangeExceptionsuch as:What's in this PR:
RichTextViewModel.NSTextStoragefor each update transaction.Note
I totally understand if you don't want to add tests as part of this fix or would prefer another testing approach. Feel free to delete the first commit or request that I delete it.
Reproduction
I was not always able to reproduce the crash organically but I did experience first-hand at least once. The steps to reproduce in #370 are accurate though. I have included a unit test that does consistently reproduce the crash and verifies the fix.
The first commit in this branch adds regression tests without the production fix. To verify the crash, check out that commit and run the focused test suite:
Expected result on the first commit: the test process crashes with
NSRangeException/NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds.How to Test
On the final branch, run the same focused test suite:
Expected result: all
RichTextViewModelTestspass.Related Issue
Fixes #370.