Merge pull request #11135 from Zellic/ls-nonutf8-hidden

ls: Treat paths starting with a dot as hidden even if they contain invalid UTF-8.
This commit is contained in:
Sylvestre Ledru
2026-02-27 09:24:48 +01:00
committed by GitHub
2 changed files with 13 additions and 4 deletions
+1 -4
View File
@@ -2399,10 +2399,7 @@ fn is_hidden(file_path: &DirEntry) -> bool {
}
#[cfg(not(windows))]
{
file_path
.file_name()
.to_str()
.is_some_and(|res| res.starts_with('.'))
file_path.file_name().as_encoded_bytes().starts_with(b".")
}
}
+12
View File
@@ -7107,3 +7107,15 @@ fn test_ls_recursive_no_fd_leak() {
.succeeds()
.stderr_is("");
}
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn test_ls_non_utf8_hidden() {
use std::{ffi::OsStr, os::unix::ffi::OsStrExt};
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch(OsStr::from_bytes(b".hidden\x80"));
scene.ucmd().succeeds().stdout_does_not_contain(".hidden");
}