Don't expanding globs if user pass variables. (#11946)

# Description
Fixes: #11912

# User-Facing Changes
After this change: 
```
let x = '*.nu'; ^echo $x
```
will no longer expand glob.
If users still want to expand glob, there are also 3 ways to do this:
```
# 1. use spread operation with `glob` command
let x = '*.nu'; ^echo ...(glob $x)
```
# Tests + Formatting
Done

# After Submitting
NaN
This commit is contained in:
Wind
2024-02-28 23:05:09 +08:00
committed by GitHub
parent c6cb406a53
commit eaedb30a8c
2 changed files with 34 additions and 1 deletions

View File

@ -711,9 +711,11 @@ fn trim_expand_and_apply_arg(
// if arg is quoted, like "aa", 'aa', `aa`, or:
// if arg is a variable or String interpolation, like: $variable_name, $"($variable_name)"
// `as_a_whole` will be true, so nu won't remove the inner quotes.
let (trimmed_args, run_glob_expansion, mut keep_raw) = trim_enclosing_quotes(&arg.item);
let (trimmed_args, mut run_glob_expansion, mut keep_raw) = trim_enclosing_quotes(&arg.item);
if *arg_keep_raw {
keep_raw = true;
// it's a list or a variable, don't run glob expansion either
run_glob_expansion = false;
}
let mut arg = Spanned {
item: if keep_raw {