Skip to content

Commit 5ebe104

Browse files
authored
Merge pull request #1520 from kishikawakatsumi/string-literal-escape
Fix escape handling for emoji `#️⃣` in string literals
2 parents fad8fa5 + 4241376 commit 5ebe104

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ extension StringLiteralExprSyntax {
249249
continue
250250

251251
// Special mode: counting a sequence of pounds until we reach its end.
252-
case (true, "#"):
252+
case (true, _) where c.unicodeScalars.contains("#"):
253253
consecutivePounds += 1
254254
maxPounds = max(maxPounds, consecutivePounds)
255255
case (true, _):

Tests/SwiftSyntaxBuilderTest/StringLiteralTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ final class StringLiteralTests: XCTestCase {
7171
)
7272
}
7373
74+
func testEscapePoundEmojis() {
75+
assertBuildResult(
76+
StringLiteralExprSyntax(content: ##"foo"#️⃣"bar"##),
77+
"""
78+
##"foo"#️⃣"bar"##
79+
"""
80+
)
81+
}
82+
7483
func testEscapeInteropolation() {
7584
assertBuildResult(
7685
StringLiteralExprSyntax(content: ###"\##(foobar)\#(foobar)"###),

0 commit comments

Comments
 (0)