Repository navigation
[MessageHandling] Decode valid JSON surrogate pairs - #3464
Conversation
There was a problem hiding this comment.
Thank you!
Although this has been unreachable as long as both the compiler and the plugin are using this JSON encoder/decoder, this change is good for spec compliance!
Just a few nit-picks, and please fix the format as https://github.com/swiftlang/swift-syntax/blob/main/CONTRIBUTING.md#formatting
| let decoded = try json.withUTF8 { try JSON.decode(String.self, from: $0) } | ||
| XCTAssertEqual(decoded, "𐐷") | ||
| } catch { | ||
| XCTFail("Decoding valid surrogate pair failed") |
There was a problem hiding this comment.
I don't think this should be wrapped with do {} catch {}. the test method can be throws
| // Valid '𐐷' (U+10437) character | ||
| assertRoundTrip( | ||
| of: "𐐷", | ||
| expectedJSON: #""𐐷""# |
There was a problem hiding this comment.
Since JSON.encode() always emits this as a bare UTF8 sequence, this test would not hit the escaped UTF16 sequence code path. Since equivalent path is covered by testComplexStruct (🛑 emoji), I don't think this test is needed.
f0f81f9 to
d9a8db7
Compare
d9a8db7 to
68f8cb1
Compare
|
Thank you for review. I am new to SwiftSyntax. I looked for contribution opportunities by checking FIXME comments in the source code and reviewing recent issues. This PR addresses the surrogate-pair decoding gap I found. Did the following change:
I amended the commit and rebased the branch onto latest main, also ran the focused test, and it passed. |
|
@rintaro I noticed that the existing tests use XCTest. Is there a plan to migrate swift-syntax to Swift Testing, or should new tests continue to use XCTest? |
|
@swift-ci Please test |
This repository still supports Swift 5.9 toolchain, which I don't think includes swift-testing, not 100% sure. Line 1 in 0a52cc4 |
|
@swift-ci Please test |
This PR adds support to decode valid JSON surrogate pairs in string escapes. The decoder now checks for a trail surrogate after a lead surrogate. The decoder still rejects unpaired surrogates. I verified this by running the local tests with
swift test --filter JSONTests.Example
The decoder rejected some characters, such as emojis, when JSON used surrogate pairs.