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-10896] Bridging from Swift.String to NSString drops U+FEFF chacacter at the beginning #4485

Open
swift-ci opened this issue Jun 9, 2019 · 2 comments
Assignees

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Jun 9, 2019

Previous ID SR-10896
Radar None
Original Reporter 1024jp (JIRA User)
Type Bug
Environment

Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)

Target: x86_64-apple-darwin18.6.0

macOS 10.14.5 / Xcode 10.2.1 (10E1001)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @Catfish-Man
Priority Medium

md5: bc2f601a88bc080ddf2da69443eeb674

Issue Description:

Since Swift 5, and also on Swift 5.1, bridging a short string from Swift.String to NSString drops U+FEFF character at the beginning.

let bom = "\u{FEFF}" // U+FEFF (ZERO WIDTH NO-BREAK SPACE)
bom.count // -> 1
"\(bom)abc".count // -> 4
NSString(string: bom).length // -> 0 (correct: 1)
NSString(string: "\(bom)abc").length // -> 3 (correct: 4)
NSString(string: "\(bom)\(bom)abc").length // -> 4 (correct: 5)
NSString(string: "a\(bom)bc").length // -> 4
NSString(string: "\(bom)234567890123").length // -> 12 (correct: 13)
NSString(string: "\(bom)2345678901234").length // -> 14

This issue arises also when the string was bridged to NSString implicitly.

let string = "\(bom)abc"
let middleIndex = string.index(string.startIndex, offsetBy: 2)
string.enumerateSubstrings(in: middleIndex..<string.endIndex, options: .byLines) { (_, _, _, _) in }  // <- crash

CC: @milseman This is about the issue I told you in the Swift lab at WWDC.

@milseman
Copy link
Mannequin

milseman mannequin commented Jun 10, 2019

CC @Catfish-Man, who was looking at a fix to a related issue

@Catfish-Man
Copy link
Member

Half-fixed in apple/swift#25957

It now works correctly with "… as NSString", but remains incorrect with "NSString(string: …)"

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants