diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index d74c65cc5..def105ae5 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -475,7 +475,7 @@ fn parse_usize(matches: &ArgMatches, opt: &str) -> Option let i = value_to_parse.0; let option = value_to_parse.1; i.parse().map_err(|_e| PrError::EncounteredErrors { - msg: format!("invalid {option} argument {}", i.quote()), + msg: format!("invalid -{option} argument {}", i.quote()), }) }; matches @@ -771,6 +771,11 @@ fn build_options( }) }); let start_column_option = match res { + Some(Ok(0)) => { + return Err(PrError::EncounteredErrors { + msg: "invalid --column argument '0'".to_string(), + }); + } Some(res) => Some(res?), None => None, }; @@ -778,6 +783,11 @@ fn build_options( // --column has more priority than -column let column_option_value = match parse_usize(matches, options::COLUMN) { + Some(Ok(0)) => { + return Err(PrError::EncounteredErrors { + msg: "invalid --column argument '0'".to_string(), + }); + } Some(res) => Some(res?), None => start_column_option, }; diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 02735a2ab..26403b6f4 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -873,3 +873,19 @@ fn test_expand_tab_does_not_consume_next_argument() { new_ucmd!().args(&["-ea", test_file_path]).succeeds(); new_ucmd!().args(&["-ea1", test_file_path]).succeeds(); } + +#[test] +fn test_zero_columns() { + new_ucmd!() + .arg("--column=0") + .fails_with_code(1) + .stderr_contains("pr: invalid --column argument '0'"); +} + +#[test] +fn test_zero_columns_shortcut() { + new_ucmd!() + .arg("-0") + .fails_with_code(1) + .stderr_contains("pr: invalid --column argument '0'"); +}