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-9820] String.subscript using Range with misaligned Index created by UTF16View is not compatible between Swift 4.x and Swift 5 #52237

Open
norio-nomura opened this issue Jan 31, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@norio-nomura
Copy link
Contributor

Previous ID SR-9820
Radar None
Original Reporter @norio-nomura
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: b55a652d4db290b2abfab16ca02d063e

relates to:

  • SR-9802 String.subscript using Range with misaligned Index created by UTF8View is not compatible between Swift 4.x and Swift 5

Issue Description:

It seems String.UTF16View.index(before:) is also not compatible between Swift 4.x and Swift 5.

$ pbpaste
func printUnicodeScalars<S: StringProtocol>(_ string: S) {
    print(string.unicodeScalars.map {
        "\\u{\(String($0.value, radix: 16))}"
    }.joined())
}
// https://emojipedia.org/family-man-woman-girl-boy/
let family = "\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}\u{200d}\u{1f466}"
printUnicodeScalars(family)

let utf16Index = family.utf16.index(before: family.utf16.endIndex)
let utf16Before = String(family[..<utf16Index])
printUnicodeScalars(utf16Before)

let utf16After = String(family[utf16Index...])
printUnicodeScalars(utf16After)

printUnicodeScalars(utf16Before + utf16After)
print(utf16After.utf16.count)
$ pbpaste|xcrun --toolchain org.swift.42120181030a swift -
\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}\u{200d}\u{1f466}
\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}\u{200d}\u{fffd}
\u{fffd}
\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}\u{200d}\u{1f466}
1
$ pbpaste|xcrun --toolchain org.swift.5020190129a swift -
\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}\u{200d}\u{1f466}
\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}\u{200d}
\u{1f466}
\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}\u{200d}\u{1f466}
2
@norio-nomura
Copy link
Contributor Author

While testing this, I encountered crashes and filed:
https://bugs.swift.org/browse/SR-9822
https://bugs.swift.org/browse/SR-9823

@belkadan
Copy link
Contributor

cc @milseman

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants