diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index f5c5662aa19..19e9f2a0c89 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -757,22 +757,29 @@ fn open(path: &str) -> Result, PrError> { |i| { let path_string = path.to_string(); match i.file_type() { - #[cfg(unix)] - ft if ft.is_block_device() => Err(PrError::UnknownFiletype { file: path_string }), - #[cfg(unix)] - ft if ft.is_char_device() => Err(PrError::UnknownFiletype { file: path_string }), - #[cfg(unix)] - ft if ft.is_fifo() => Err(PrError::UnknownFiletype { file: path_string }), #[cfg(unix)] ft if ft.is_socket() => Err(PrError::IsSocket { file: path_string }), ft if ft.is_dir() => Err(PrError::IsDirectory { file: path_string }), - ft if ft.is_file() || ft.is_symlink() => { - Ok(Box::new(File::open(path).map_err(|e| PrError::Input { - source: e, - file: path.to_string(), - })?) as Box) + + ft => { + #[allow(unused_mut)] + let mut is_valid = ft.is_file() || ft.is_symlink(); + + #[cfg(unix)] + { + is_valid = + is_valid || ft.is_char_device() || ft.is_block_device() || ft.is_fifo(); + } + + if is_valid { + Ok(Box::new(File::open(path).map_err(|e| PrError::Input { + source: e, + file: path.to_string(), + })?) as Box) + } else { + Err(PrError::UnknownFiletype { file: path_string }) + } } - _ => Err(PrError::UnknownFiletype { file: path_string }), } }, ) diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 1fa91dab2e9..0bb161fb8a8 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -610,3 +610,9 @@ fn test_help() { fn test_version() { new_ucmd!().arg("--version").succeeds(); } + +#[cfg(unix)] +#[test] +fn test_pr_char_device_dev_null() { + new_ucmd!().arg("/dev/null").succeeds(); +}