Skip to content

Commit 451c907

Browse files
committed
Fix an issue where we weren't properly escaping backslashes in quoted strings when converting to the DSL.
1 parent 88dc9dd commit 451c907

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
@@ -578,7 +578,7 @@ extension PrettyPrinter {
578578
extension String {
579579
// TODO: Escaping?
580580
fileprivate var _quoted: String {
581-
"\"\(self._replacing("\"", with: "\\\""))\""
581+
"\"\(self._replacing("\\", with: "\\\\")._replacing("\"", with: "\\\""))\""
582582
}
583583
}
584584

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)