Issue/fix crash on toggle quotes #1203
Merged
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 #wordpress-mobile/WordPress-iOS#11948
This issues fixes a crash on the app when toggling a blockquote in the middle of the following HTML
The crash was happening inside the method
func replaceOcurrences(of stringToFind: String, with replacementString: String, within range: NSRange) {When I first try to unit test the original method using a vanilla NSMutableAttributedString everything was running correctly. Then I remembered that our implementation of TextStorage while it uses an NSMutableString it has special handling for the string property.
This was the reason that the range was getting invalid, after the first replacement was made and then caused a crash on the second tentative to math the occurrence.
The bug was fixed by making sure the range where we are trying to match is completely recalculated after a replacement.
To test:
Quote Two