From 6cdd8a2b07f18333c62e0ba40dd5ce107d7c7ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=B5=20Anh=20Duy?= Date: Sat, 26 Jun 2021 04:14:54 +0800 Subject: [PATCH] Fix string interpolation is not working with external command (#3686) --- crates/nu-parser/src/parse.rs | 4 +++- tests/shell/pipeline/commands/external.rs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index e57a31b3a4..7d9173b34e 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -730,7 +730,9 @@ fn parse_external_arg( lite_arg: &Spanned, scope: &dyn ParserScope, ) -> (SpannedExpression, Option) { - if lite_arg.item.starts_with('$') || lite_arg.item.starts_with('(') { + if lite_arg.item.starts_with('$') { + parse_dollar_expr(lite_arg, scope) + } else if lite_arg.item.starts_with('(') { parse_full_column_path(lite_arg, scope) } else { ( diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index 6813a7a4aa..35fe51c5f3 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -368,4 +368,25 @@ mod external_command_arguments { }, ) } + + #[test] + fn string_interpolation_with_an_external_command() { + Playground::setup( + "string_interpolation_with_an_external_command", + |dirs, sandbox| { + sandbox.mkdir("cd"); + + sandbox.with_files(vec![EmptyFile("cd/jonathan_likes_cake.txt")]); + + let actual = nu!( + cwd: dirs.test(), pipeline( + r#" + ^ls $"(pwd)/cd" + "# + )); + + assert_eq!(actual.out, "jonathan_likes_cake.txt"); + }, + ) + } }