From cd2df83ddc3f3f9f6b184db4ed4b8f649b57594b Mon Sep 17 00:00:00 2001 From: Herlon Aguiar Date: Sun, 24 Apr 2022 21:15:33 +0200 Subject: [PATCH] nu-command/filesystem: clean whitespaces from paths in cd and open (#5310) --- crates/nu-command/src/filesystem/cd.rs | 5 ++++- crates/nu-command/src/filesystem/open.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/filesystem/cd.rs b/crates/nu-command/src/filesystem/cd.rs index f129509fde..d223b30ba4 100644 --- a/crates/nu-command/src/filesystem/cd.rs +++ b/crates/nu-command/src/filesystem/cd.rs @@ -58,7 +58,10 @@ impl Command for Cd { (cwd.to_string_lossy().to_string(), v.span) } } else { - let path = match nu_path::canonicalize_with(&v.item, &cwd) { + let path_no_whitespace = + &v.item.trim_end_matches(|x| matches!(x, '\x09'..='\x0d')); + + let path = match nu_path::canonicalize_with(path_no_whitespace, &cwd) { Ok(p) => { if !p.is_dir() { return Err(ShellError::NotADirectory(v.span)); diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index 5b9d6cc331..fc4fcc7d1a 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -83,7 +83,8 @@ impl Command for Open { } }; let arg_span = path.span; - let path = Path::new(&path.item); + let path_no_whitespace = &path.item.trim_end_matches(|x| matches!(x, '\x09'..='\x0d')); + let path = Path::new(path_no_whitespace); if permission_denied(&path) { #[cfg(unix)]