diff --git a/src/unindent.rs b/src/unindent.rs index a9f1259e52..c27673b233 100644 --- a/src/unindent.rs +++ b/src/unindent.rs @@ -18,7 +18,13 @@ pub fn unindent(text: &str) -> String { let last = i == lines.len() - 1; let replacement = match (blank, first, last) { - (true, false, false) => "\n", + (true, false, false) => { + if line.ends_with("\r\n") { + "\r\n" + } else { + "\n" + } + } (true, _, _) => "", (false, _, _) => &line[common_indentation.len()..], }; @@ -67,6 +73,7 @@ mod tests { assert_eq!(unindent(""), ""); assert_eq!(unindent(" foo\n bar"), "foo\nbar"); assert_eq!(unindent(" foo\n bar\n\n"), "foo\nbar\n"); + assert_eq!(unindent(" foo\r\n\r\n bar\r\n"), "foo\r\n\r\nbar\r\n"); assert_eq!( unindent( diff --git a/tests/string.rs b/tests/string.rs index 8e8118a40f..83e4b21eb8 100644 --- a/tests/string.rs +++ b/tests/string.rs @@ -686,3 +686,18 @@ fn unicode_escape_unterminated() { ) .failure(); } + +#[test] +fn indented_string_crlf_blank_lines_keep_crlf() { + let test = Test::new(); + fs::write( + test.justfile_path(), + "x := '''\r\nfoo\r\n\r\nbar\r\n'''\r\n", + ) + .unwrap(); + test + .args(["--evaluate", "x"]) + .unindent_stdout(false) + .stdout("foo\r\n\r\nbar\r\n") + .success(); +}