Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/uu/pathchk/src/pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ pub fn uu_app() -> Command {

/// check a path, given as a slice of it's components and an operating mode
fn check_path(mode: &Mode, path: &[String]) -> bool {
// GNU rejects an empty file name in any portability mode before touching the filesystem.
if !matches!(mode, Mode::Default) && path.join("/").is_empty() {
show_error!("{}", translate!("pathchk-error-empty-file-name"));
return false;
}
match *mode {
Mode::Basic => check_basic(path),
Mode::Extra => check_default(path) && check_extra(path),
Expand Down
17 changes: 17 additions & 0 deletions tests/by-util/test_pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ fn test_posix_all() {
new_ucmd!().args(&["-p", "-P", ""]).fails().no_stdout();
}

#[test]
#[cfg(unix)]
fn test_empty_path_portability_message() {
// In every portability mode (-p, -P, --portability) GNU reports an empty
// file name with the program-name prefix and before any filesystem check.
for flag in ["-p", "-P", "--portability"] {
new_ucmd!()
.args(&[flag, ""])
.fails()
.stderr_only("pathchk: empty file name\n");
}
new_ucmd!()
.args(&["-p", "-P", ""])
.fails()
.stderr_only("pathchk: empty file name\n");
}

#[test]
#[cfg(target_os = "linux")]
fn test_pathchk_non_utf8_paths() {
Expand Down
Loading