mirror of
https://github.com/nushell/nushell.git
synced 2024-11-08 17:44:27 +01:00
Fix path_contains_hidden_folder (#6173)
* Fix path_contains_hidden_folder Signed-off-by: nibon7 <nibon7@163.com> * add test Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
parent
87823b0cb5
commit
7c49a42b68
@ -343,11 +343,7 @@ fn is_hidden_dir(dir: impl AsRef<Path>) -> bool {
|
||||
}
|
||||
|
||||
fn path_contains_hidden_folder(path: &Path, folders: &[PathBuf]) -> bool {
|
||||
let path_str = path.to_str().expect("failed to read path");
|
||||
if folders
|
||||
.iter()
|
||||
.any(|p| path_str.starts_with(&p.to_str().expect("failed to read hidden paths")))
|
||||
{
|
||||
if folders.iter().any(|p| path.starts_with(p.as_path())) {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
|
@ -513,3 +513,28 @@ fn list_a_directory_not_exists() {
|
||||
assert!(actual.err.contains("directory not found"));
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn list_directory_contains_invalid_utf8() {
|
||||
use std::ffi::OsStr;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
|
||||
Playground::setup(
|
||||
"ls_test_directory_contains_invalid_utf8",
|
||||
|dirs, _sandbox| {
|
||||
let v: [u8; 4] = [7, 196, 144, 188];
|
||||
let s = OsStr::from_bytes(&v);
|
||||
|
||||
let cwd = dirs.test();
|
||||
let path = cwd.join(s);
|
||||
|
||||
std::fs::create_dir_all(&path).expect("failed to create directory");
|
||||
|
||||
let actual = nu!(cwd, "ls");
|
||||
|
||||
assert!(actual.out.contains("warning: get non-utf8 filename"));
|
||||
assert!(actual.err.contains("No matches found for"));
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user