Skip to content

Restore more-correct behavior of getting the full contents of bridged NSStrings containing invalid UTF-8 #26172

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

Merged

Conversation

Catfish-Man
Copy link
Contributor

@Catfish-Man Catfish-Man commented Jul 16, 2019

5.1 version of #26152

(cherry picked from commit d091ecb)

Fixes rdar://problem/53119693

Explanation: NSStrings can be created with un-paired UTF16 surrogates, which will then cause them to fail to transcode to UTF8. We previously avoided this (and correctly repaired the invalid contents with the unicode replacement character) by asking for UTF16, one at a time, and doing our own conversion. In Swift 5.1 we switched to a bulk-access NSString API that does the transcoding for us, which caused our handling of invalid contents like this to preconditionFailure instead of repairing.

The fix is to add the old one at a time code back as a recovery path.

Scope: Swift Standard Library

Issue: rdar://problem/53119693

Risk: Low. This is a change of behavior, but it's restoring 4.2 behavior; additionally it only comes into effect in edge cases, since unpaired surrogates are invalid.

Testing: Regular tests + new automated tests specifically for this issue

Reviewer: @milseman

… NSStrings containing invalid UTF-8

(cherry picked from commit d091ecb)
@Catfish-Man Catfish-Man self-assigned this Jul 16, 2019
@Catfish-Man
Copy link
Contributor Author

@swift-ci please test

@Catfish-Man
Copy link
Contributor Author

@swift-ci nominate

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

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

LGTM

@Catfish-Man Catfish-Man merged commit 19e5152 into swiftlang:swift-5.1-branch Jul 17, 2019
@Catfish-Man Catfish-Man deleted the serrated-surrogates-5.1 branch July 17, 2019 20:49
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.

2 participants