Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SR-8689: Fix crash with NSMutableString.replaceOccurrences(of:with:options:) #1687

Merged
merged 2 commits into from
Sep 13, 2018

Conversation

spevans
Copy link
Contributor

@spevans spevans commented Sep 8, 2018

  • "\r\n" is treated as a single character, but so are "\r" and "\n"
    so use rangeOfComposedCharacterSequence(at:) to find the range of the
    decomposed character.

…tions:)

- "\r\n" is treated as a single character, but so are "\r" and "\n"
  so use rangeOfComposedCharacterSequence(at:) to find the range of the
  decomposed character.
@spevans
Copy link
Contributor Author

spevans commented Sep 8, 2018

@swift-ci test

@spevans spevans requested a review from itaiferber September 9, 2018 17:42
let min = _storage.utf16.index(start, offsetBy: range.location).samePosition(in: _storage) ??
_storage.utf16.index(start, offsetBy: _storage.rangeOfComposedCharacterSequence(at: range.location).location)

let max = _storage.utf16.index(start, offsetBy: range.location + range.length).samePosition(in: _storage) ?? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, though from a style perspective it might be nice to make these consistent (either both as a closure or not — I prefer the closure).

In the cases where we might expect to fall into the rangeOfComposedCharacterSequence(at:) case for both min and max, it's likely worth factoring out that computation, I think — there are cases where it's not so cheap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct that the computation for rangeOfComposedCharacterSequence(at:) can only be reused if range.length == 0. Is that a valid input?

Copy link
Contributor

@itaiferber itaiferber Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️
You're totally right, of course — read too hastily. Nothing to factor out there.

@spevans
Copy link
Contributor Author

spevans commented Sep 12, 2018

@swift-ci test

@itaiferber
Copy link
Contributor

Looks good!

@spevans
Copy link
Contributor Author

spevans commented Sep 13, 2018

@swift-ci please test

@spevans
Copy link
Contributor Author

spevans commented Sep 13, 2018

@swift-ci test and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants