pr: exit with code 1 if --column argument is zero (#11750)

This commit is contained in:
Devel08
2026-04-20 23:41:53 +03:00
committed by GitHub
parent ab786f50ef
commit e4987f0dbd
2 changed files with 27 additions and 1 deletions
+11 -1
View File
@@ -475,7 +475,7 @@ fn parse_usize(matches: &ArgMatches, opt: &str) -> Option<Result<usize, PrError>
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,
};
+16
View File
@@ -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'");
}