mirror of
https://github.com/nushell/nushell.git
synced 2025-06-04 00:56:11 +02:00
fix: implicitly running .ps1 scripts with spaces in path (#15781)
- this PR should close #15757 # Description > [!NOTE] > [`-File <filePath> <args>`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1#-file----filepath-args) > - Enter the script filepath and any parameters > - All values typed after the File parameter are interpreted as the script filepath and parameters passed to that script. > [!NOTE] > [`-Command`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1#-command) > - The value of Command can be -, a _script block_, or a _string_. > - In `cmd.exe` (and other externall callers), there is no such thing as a _script block_, so the value passed to Command is always a _**string**_. > - A string passed to Command is still executed as PowerShell code. > [!NOTE] > [Call operator `&`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-5.1#call-operator-) > - Runs a command, ***script***, or script block. Basically using `-Command` to run scripts would require _another_ layer of quoting and escaping. It looks like `-File` is the way to run powershell scripts as an external caller. # User-Facing Changes # Tests + Formatting # After Submitting Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
This commit is contained in:
parent
833471241a
commit
6906a0ca50
@ -187,12 +187,10 @@ impl Command for External {
|
|||||||
}
|
}
|
||||||
} else if potential_powershell_script {
|
} else if potential_powershell_script {
|
||||||
command.args([
|
command.args([
|
||||||
"-Command",
|
"-File",
|
||||||
&path_to_ps1_executable.unwrap_or_default().to_string_lossy(),
|
&path_to_ps1_executable.unwrap_or_default().to_string_lossy(),
|
||||||
]);
|
]);
|
||||||
for arg in &args {
|
command.args(args.into_iter().map(|s| s.item));
|
||||||
command.raw_arg(arg.item.clone());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
command.args(args.into_iter().map(|s| s.item));
|
command.args(args.into_iter().map(|s| s.item));
|
||||||
}
|
}
|
||||||
|
@ -536,6 +536,25 @@ fn can_run_ps1_files(prefix: &str) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[apply(run_external_prefixes)]
|
||||||
|
fn can_run_ps1_files_with_space_in_path(prefix: &str) {
|
||||||
|
use nu_test_support::fs::Stub::FileWithContent;
|
||||||
|
Playground::setup("run_a_windows_ps_file", |dirs, sandbox| {
|
||||||
|
sandbox
|
||||||
|
.within("path with space")
|
||||||
|
.with_files(&[FileWithContent(
|
||||||
|
"foo.ps1",
|
||||||
|
r#"
|
||||||
|
Write-Host Hello World
|
||||||
|
"#,
|
||||||
|
)]);
|
||||||
|
|
||||||
|
let actual = nu!(cwd: dirs.test().join("path with space"), "{}foo.ps1", prefix);
|
||||||
|
assert!(actual.out.contains("Hello World"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[rstest]
|
#[rstest]
|
||||||
#[case("^")]
|
#[case("^")]
|
||||||
#[case("run-external ")]
|
#[case("run-external ")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user