head: fix error message when input is a directory (#11541)

* head: fix error message when input is a directory

* head: check for directory before trying to open
This commit is contained in:
Alvaro Guimaraes
2026-03-30 16:54:50 +02:00
committed by GitHub
parent f41a088522
commit d8688183ff
2 changed files with 17 additions and 2 deletions
+8
View File
@@ -911,3 +911,11 @@ fn test_head_non_utf8_paths() {
assert!(output.contains("line3"));
}
// Test that head handles non-UTF-8 file names without crashing
#[test]
fn test_do_not_attempt_to_read_a_directory() {
new_ucmd!()
.arg(".")
.fails_with_code(1)
.stderr_contains("error reading '.'");
}