Skip to content

Commit 935e137

Browse files
authored
Merge pull request #436 from apple/dewing/93676693_Quote_backslash
Escape backslashes properly when converting to the DSL
2 parents 81b84d2 + 21b30cb commit 935e137

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)