Fix out of bounds crash of truncated token replacement#75
Open
Econa77 wants to merge 1 commit into
Open
Conversation
Econa77
commented
Apr 2, 2021
| // the first line we replace, we'll truncate it, after that, we 100% replace lines of the original string with truncation lines | ||
| for (index, tokenLine) in tokenLines.enumerated() { | ||
| let originalIndex = self.numberOfLines - tokenLines.count + index | ||
| let originalIndex = lines.count - tokenLines.count + index |
Author
There was a problem hiding this comment.
The settings when the app crashed were as follows.
- self.numberOfLines:
5 - lines.count:
4 - tokenLines.count:
2
As a result, the originalIndex was out of range of lines and crashed at times other than the first replacement.
When there are many lines with only line breaks, the number of lines in lines may not match with numberOfLines, so the index is acquired from the number of lines in lines.
Author
|
The snapshot test is failing, but when I try it, it seems to fail the same before the change. |
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.
No description provided.