-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
…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.
@swift-ci test |
Foundation/NSString.swift
Outdated
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) ?? { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@swift-ci test |
Looks good! |
@swift-ci please test |
@swift-ci test and merge |
so use rangeOfComposedCharacterSequence(at:) to find the range of the
decomposed character.