diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 99af7e60e6..df691b8f22 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -1477,8 +1477,18 @@ pub fn parse_string_interpolation( end, }; let str_contents = working_set.get_span_contents(span); + + let str_contents = if double_quote { + let (str_contents, err) = unescape_string(str_contents, span); + error = error.or(err); + + str_contents + } else { + str_contents.to_vec() + }; + output.push(Expression { - expr: Expr::String(String::from_utf8_lossy(str_contents).to_string()), + expr: Expr::String(String::from_utf8_lossy(&str_contents).to_string()), span, ty: Type::String, custom_completion: None, diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index 481df1afc6..877e06f798 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -218,6 +218,11 @@ fn string_interpolation_paren_test3() -> TestResult { run_test(r#"$"('(')("test")test(')')""#, "(testtest)") } +#[test] +fn string_interpolation_escaping() -> TestResult { + run_test(r#"$"hello\nworld" | lines | length"#, "2") +} + #[test] fn capture_multiple_commands() -> TestResult { run_test(