Skip to content

Commit fa7ff05

Browse files
authored
Merge pull request #1009 from ahoppen/ahoppen/escape-backslash
Fix a bug where the StringLiteralExpr convenience initializer would add too few `#`s to correctly contain a backslash
2 parents 1bde900 + e5f0d3c commit fa7ff05

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Sources/SwiftSyntaxBuilder/ConvenienceInitializers/StringLiteralExprConvenienceInitializers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private let rawStringPotentialEscapesPattern = try! NSRegularExpression(
1919
pattern: [
2020
#""(#*)"#, // Match potential opening delimiters
2121
#"(#*)""#, // Match potential closing delimiters
22-
#"\\(#*)\("#, // Match potential interpolations
22+
#"\\(#*)"#, // Match potential interpolations
2323
].joined(separator: "|")
2424
)
2525

Tests/SwiftSyntaxBuilderTest/StringLiteralTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ final class StringLiteralTests: XCTestCase {
3434
AssertBuildResult(builder, expected, line: line)
3535
}
3636
}
37+
38+
func testEscapeBackslash() {
39+
AssertBuildResult(StringLiteralExpr(content: #"\"#), ##"""
40+
#"\"#
41+
"""##)
42+
}
3743
}

0 commit comments

Comments
 (0)