-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix for a crash in String.substring(with:) [SR-2483] #647
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
Conversation
could you possibly add a unit test to verify this behavior? |
@phausler : I am no longer comfortable with my fix. The API reference says |
Certainly, it might be useful to verify the ground truth of how that behaves in objc - since that is our baseline here |
8ccc37a
to
4d87308
Compare
When using |
93aa217
to
8f6103a
Compare
@swift-ci please test |
Updated this to include a handful of corner cases with surrogate pairs and |
@swift-ci please test |
//the range probably breaks surrogate pairs at both the ends | ||
guard min.advanced(by: 1) <= max.advanced(by: -1) else { return prefix + suffix } | ||
|
||
let substr = String(_storage.utf16[min.advanced(by: 1)..<max.advanced(by: -1)])! |
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.
After all the prior checks, I think this can be safely unwrapped.
@swift-ci please test |
This took me a while to review because I was digging through the Darwin version, which really defers this operation to CFString. That's where the replacement character substitution happens. In the long term we may want to make NSString.swift do something similar so we don't end up replicating this logic in two places, but in the short term this fix seems appropriate. |
@swift-ci test and merge |
I think this is just one way to fix: https://bugs.swift.org/browse/SR-2483
I've documented some additional findings in the bug report.