Skip to content

Commit 870adfa

Browse files
DaveEwinghamishknight
authored andcommitted
Fix an issue where we weren't properly escaping backslashes in quoted strings when converting to the DSL.
1 parent 78bd812 commit 870adfa

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ extension PrettyPrinter {
576576
extension String {
577577
// TODO: Escaping?
578578
fileprivate var _quoted: String {
579-
"\"\(self._replacing("\"", with: "\\\""))\""
579+
"\"\(self._replacing("\\", with: "\\\\")._replacing("\"", with: "\\\""))\""
580580
}
581581
}
582582

Tests/RegexTests/RenderDSLTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,12 @@ extension RenderDSLTests {
114114
""")
115115
}
116116
}
117+
118+
func testQuoting() throws {
119+
try testConversion(#"\\\"a\""#, #"""
120+
Regex {
121+
"\\\"a\""
122+
}
123+
"""#)
124+
}
117125
}

0 commit comments

Comments
 (0)