From 199aa2ad3a2f7499b87d7fe13a7de2e76469a9ba Mon Sep 17 00:00:00 2001 From: Kither <61571510+Kither12@users.noreply.github.com> Date: Fri, 4 Oct 2024 20:44:40 +0700 Subject: [PATCH] escape dollarsign in tab completion (#13988) # Description fixes #13518 This pr escapes file/directory names, which start with a dollar sign since it's being interpreted as a variable. # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-cli/src/completions/completion_common.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/nu-cli/src/completions/completion_common.rs b/crates/nu-cli/src/completions/completion_common.rs index 6dd59da853..438ce2a1f0 100644 --- a/crates/nu-cli/src/completions/completion_common.rs +++ b/crates/nu-cli/src/completions/completion_common.rs @@ -267,8 +267,10 @@ pub fn escape_path(path: String, dir: bool) -> String { let filename_contaminated = !dir && path.contains(['\'', '"', ' ', '#', '(', ')']); let dirname_contaminated = dir && path.contains(['\'', '"', ' ', '#']); let maybe_flag = path.starts_with('-'); + let maybe_variable = path.starts_with('$'); let maybe_number = path.parse::().is_ok(); - if filename_contaminated || dirname_contaminated || maybe_flag || maybe_number { + if filename_contaminated || dirname_contaminated || maybe_flag || maybe_variable || maybe_number + { format!("`{path}`") } else { path