From 08e495ea67d71efa144cbe678e705c6cfbebb7a0 Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Sat, 7 May 2022 04:21:29 -0700 Subject: [PATCH] Enable string interpolation for environment shorthand (#5463) --- crates/nu-parser/src/parser.rs | 17 ++++++++++------- tests/shell/environment/env.rs | 9 +++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 57b47cc50a..9e2ed63473 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -4287,13 +4287,16 @@ pub fn parse_expression( }, ); let rhs = if spans[pos].start + point < spans[pos].end { - parse_string_strict( - working_set, - Span { - start: spans[pos].start + point, - end: spans[pos].end, - }, - ) + let rhs_span = Span { + start: spans[pos].start + point, + end: spans[pos].end, + }; + + if working_set.get_span_contents(rhs_span).starts_with(b"$") { + parse_dollar_expr(working_set, rhs_span, expand_aliases_denylist) + } else { + parse_string_strict(working_set, rhs_span) + } } else { ( Expression { diff --git a/tests/shell/environment/env.rs b/tests/shell/environment/env.rs index 8669ff6246..dedb24d6cc 100644 --- a/tests/shell/environment/env.rs +++ b/tests/shell/environment/env.rs @@ -22,6 +22,15 @@ fn env_shorthand_with_equals() { assert_eq!(actual.out, "my_module=info"); } +#[test] +fn env_shorthand_with_interpolation() { + let actual = nu!(cwd: ".", r#" + let num = 123 + FOO=$"($num) bar" echo $env.FOO + "#); + assert_eq!(actual.out, "123 bar"); +} + #[test] fn env_shorthand_with_comma_equals() { let actual = nu!(cwd: ".", r#"