From efac712f622d516dbf38f97e20d4424143276e4c Mon Sep 17 00:00:00 2001 From: JT Date: Wed, 12 May 2021 16:20:29 +1200 Subject: [PATCH] Fix string interp/shorthand overlap (#3412) --- crates/nu-parser/src/parse.rs | 6 +++--- tests/shell/pipeline/commands/internal.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index 52ee8559e4..191a04751f 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -1738,9 +1738,9 @@ fn expand_shorthand_forms( lite_pipeline: &LitePipeline, ) -> (LitePipeline, Option, Option) { if !lite_pipeline.commands.is_empty() { - if lite_pipeline.commands[0].parts[0].item == "=" { - (lite_pipeline.clone(), None, None) - } else if lite_pipeline.commands[0].parts[0].contains('=') { + if lite_pipeline.commands[0].parts[0].contains('=') + && !lite_pipeline.commands[0].parts[0].starts_with('$') + { let assignment: Vec<_> = lite_pipeline.commands[0].parts[0].split('=').collect(); if assignment.len() != 2 { ( diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 915440f951..b86d5d924d 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -137,6 +137,18 @@ fn string_interpolation_with_it_column_path() { assert_eq!(actual.out, "sammie"); } +#[test] +fn string_interpolation_shorthand_overlap() { + let actual = nu!( + cwd: ".", + r#" + $"3 + 4 = {3 + 4}" + "# + ); + + assert_eq!(actual.out, "3 + 4 = 7"); +} + #[test] fn bignum_large_integer() { let actual = nu!(