diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 6d0776a162..cb4d3bdde6 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -600,9 +600,11 @@ impl ExternalCommand { span: arg.span, }; - arg.item = nu_path::expand_tilde(arg.item) - .to_string_lossy() - .to_string(); + if !keep_raw { + arg.item = nu_path::expand_tilde(arg.item) + .to_string_lossy() + .to_string(); + } let cwd = PathBuf::from(cwd); diff --git a/crates/nu-command/tests/commands/run_external.rs b/crates/nu-command/tests/commands/run_external.rs index 94798e32bd..95a7b8e672 100644 --- a/crates/nu-command/tests/commands/run_external.rs +++ b/crates/nu-command/tests/commands/run_external.rs @@ -201,6 +201,17 @@ fn external_command_escape_args() { }) } +#[test] +fn external_command_not_expand_tilde_with_quotes() { + Playground::setup( + "external command not expand tilde with quotes", + |dirs, _| { + let actual = nu!(cwd: dirs.test(), pipeline(r#"nu --testbin nonu "~""#)); + assert_eq!(actual.out, r#"~"#); + }, + ) +} + #[cfg(windows)] #[test] fn explicit_glob_windows() {