From 6181ea5fc110e45d128424d2f7c1029b2d3a52e7 Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Sat, 14 Oct 2023 17:22:15 +0000 Subject: [PATCH] fix: only escape path containing numbers if they can be valid floating points (#10719) Refer to https://github.com/nushell/nushell/pull/10600#issuecomment-1762863791 # Description A path is escaped when it can be entirely parsed as a floating point number. This includes `nan`, `inf` and their negative counterparts since nu also supports them. # User-Facing Changes Paths with numbers that cannot be ambiguous are no longer surrounded by backticks. # Tests + Formatting # After Submitting --- crates/nu-cli/src/completions/completion_common.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/nu-cli/src/completions/completion_common.rs b/crates/nu-cli/src/completions/completion_common.rs index 393f7ec336..c8ff69246e 100644 --- a/crates/nu-cli/src/completions/completion_common.rs +++ b/crates/nu-cli/src/completions/completion_common.rs @@ -150,12 +150,9 @@ pub fn complete_item( // Fix files or folders with quotes or hashes pub fn escape_path(path: String, dir: bool) -> String { - let filename_contaminated = !dir - && path.contains([ - '\'', '"', ' ', '#', '(', ')', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - ]); + let filename_contaminated = !dir && path.contains(['\'', '"', ' ', '#', '(', ')']); let dirname_contaminated = dir && path.contains(['\'', '"', ' ', '#']); - if filename_contaminated || dirname_contaminated { + if filename_contaminated || dirname_contaminated || path.parse::().is_ok() { format!("`{path}`") } else { path