Skip to content

Commit 54bd6fd

Browse files
authored
Merge pull request #794 from harehare/fix/formatter-backslash-escaping
🐛 fix(formatter): Fix backslash escaping in interpolated strings
2 parents e6b6845 + 762c2af commit 54bd6fd

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

crates/mq-formatter/src/formatter.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ impl Formatter {
10261026
"s\"{}\"",
10271027
token
10281028
.to_string()
1029+
.replace("\\", "\\\\") // Must be first to avoid double-escaping
10291030
.replace("\"", "\\\"")
10301031
.replace("\t", "\\t")
10311032
.replace("\r", "\\r")
@@ -1870,6 +1871,11 @@ end"#
18701871
"if(test): test # comment else: test2 # comment2",
18711872
"if (test): test # comment else: test2 # comment2"
18721873
)]
1874+
#[case::interpolated_string_with_escaped_brackets(
1875+
r#"s"\\[${phrase}\\]\\(""#,
1876+
r#"s"\\[${phrase}\\]\\(""#
1877+
)]
1878+
#[case::interpolated_string_with_backslash(r#"s"\\test""#, r#"s"\\test""#)]
18731879
fn test_format(#[case] code: &str, #[case] expected: &str) {
18741880
let result = Formatter::new(None).format(code);
18751881
assert_eq!(result.unwrap(), expected);

0 commit comments

Comments
 (0)