Skip to content

Commit c89ea14

Browse files
authored
Merge pull request #1821 from kishikawakatsumi/literal-59
[5.9]Fixes wrong escape when creating a string literal where a pound sign follows a sequence of double quotes or backslashes
2 parents 8957ef3 + 1d25134 commit c89ea14

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ extension StringLiteralExprSyntax {
262262
case (true, _) where c.unicodeScalars.contains("#"):
263263
consecutivePounds += 1
264264
maxPounds = max(maxPounds, consecutivePounds)
265+
case (true, "\""), (true, "\\"):
266+
continue
265267
case (true, _):
266268
countingPounds = false
267269
consecutivePounds = 0

Tests/SwiftSyntaxBuilderTest/StringLiteralExprSyntaxTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ final class StringLiteralExprSyntaxTests: XCTestCase {
7171
)
7272
}
7373
74+
func testEscapePoundsAfterConsecutiveQuotes() {
75+
assertBuildResult(
76+
StringLiteralExprSyntax(content: ##"foobar""#"##),
77+
"""
78+
##"foobar""#"##
79+
"""
80+
)
81+
}
82+
83+
func testEscapePoundsAfterConsecutiveBackslashes() {
84+
assertBuildResult(
85+
StringLiteralExprSyntax(content: ##"foobar\\#"##),
86+
##"""
87+
##"foobar\\#"##
88+
"""##
89+
)
90+
}
91+
7492
func testEscapePoundEmojis() {
7593
assertBuildResult(
7694
StringLiteralExprSyntax(content: ##"foo"#️⃣"bar"##),

0 commit comments

Comments
 (0)