Fixed BMPString encoding#111
Conversation
Craz1k0ek
commented
Nov 26, 2025
- Fixed Incorrect ASN1BMPString encoding ExpressibleByStringLiteral #110 by using UTF-16 to encode the string literal
- Added a unit test to test the added functionality
| public init(stringLiteral value: StringLiteralType) { | ||
| self.bytes = ArraySlice(value.utf8) | ||
| self.bytes = ArraySlice(value.utf16.flatMap { codeUnit in | ||
| [UInt8(codeUnit >> 8), UInt8(codeUnit & 0xFF)] |
There was a problem hiding this comment.
| [UInt8(codeUnit >> 8), UInt8(codeUnit & 0xFF)] | |
| [UInt8(truncatingIfNeeded: codeUnit >> 8), UInt8(truncatingIfNeeded: codeUnit)] |
Separately here, I think we need to handle the case of UTF-16 surrogate pairs. We should probably detect these, and fatalError out. Seeing either a high or low surrogate is an error.
There was a problem hiding this comment.
I've updated the code. Not sure if the error message is clear enough and whether it's better to have a separate error for high and low surrogates
88617a1 to
f759527
Compare
|
Seems like the format checker needs to be appeased. |
I checked out what he was complaining about yesterday, but I couldn't figure it out. Is it the triple property tuple for testing? If you let me know, I'll update the code. |
|
It wants this diff applied: Basically, two indentation tweaks, and a trailing comma. |
f759527 to
7d8ae1f
Compare
|
Looks like this bit got missed: |
* Fixed apple#110 by using UTF-16 to encode the string literal * Added a unit test to test the added functionality
7d8ae1f to
fcaeb73
Compare
|
FWIW you can now test these fatalErrors with exit tests: https://github.com/swiftlang/swift-evolution/blob/main/proposals/testing/0008-exit-tests.md |