From 944cad35bf846adbbe69556a1a7e92fe74c44dd5 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Sun, 26 Mar 2023 17:17:51 +0800 Subject: [PATCH] When running external command, expand tilde when pass back-quoted word (#8561) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Fixes: #8542 # User-Facing Changes ## Previous ``` ❯ cat `~/TE ST/bug` cat: ~/TE ST/bug: No such file or directory ``` ## After ``` ❯ cat `~/TE ST/bug` a ``` This should be ok because We treat back-quoted strings as bare words # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --- crates/nu-command/src/system/run_external.rs | 3 ++- crates/nu-command/tests/commands/run_external.rs | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 646c0a66c3..ebda1e3446 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -778,7 +778,8 @@ fn trim_enclosing_quotes(input: &str) -> (String, bool, bool) { match (chars.next(), chars.next_back()) { (Some('"'), Some('"')) => (chars.collect(), false, true), (Some('\''), Some('\'')) => (chars.collect(), false, true), - (Some('`'), Some('`')) => (chars.collect(), true, true), + // We treat back-quoted strings as bare words, so there's no need to keep them as raw strings + (Some('`'), Some('`')) => (chars.collect(), true, false), _ => (input.to_string(), true, false), } } diff --git a/crates/nu-command/tests/commands/run_external.rs b/crates/nu-command/tests/commands/run_external.rs index 151834c54b..cd6833117f 100644 --- a/crates/nu-command/tests/commands/run_external.rs +++ b/crates/nu-command/tests/commands/run_external.rs @@ -213,6 +213,17 @@ fn external_command_not_expand_tilde_with_quotes() { ) } +#[test] +fn external_command_expand_tilde_with_back_quotes() { + Playground::setup( + "external command not expand tilde with quotes", + |dirs, _| { + let actual = nu!(cwd: dirs.test(), pipeline(r#"nu --testbin nonu `~`"#)); + assert!(!actual.out.contains("~")); + }, + ) +} + #[test] fn external_command_receives_raw_binary_data() { Playground::setup("external command receives raw binary data", |dirs, _| {