nu-command/filesystem: clean whitespaces from paths in cd and open (#5310)

This commit is contained in:
Herlon Aguiar 2022-04-24 21:15:33 +02:00 committed by GitHub
parent 3eb447030b
commit cd2df83ddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -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));

View File

@ -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)]