Skip to content

Commit e4987f0

Browse files
authored
pr: exit with code 1 if --column argument is zero (#11750)
1 parent ab786f5 commit e4987f0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/uu/pr/src/pr.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn parse_usize(matches: &ArgMatches, opt: &str) -> Option<Result<usize, PrError>
475475
let i = value_to_parse.0;
476476
let option = value_to_parse.1;
477477
i.parse().map_err(|_e| PrError::EncounteredErrors {
478-
msg: format!("invalid {option} argument {}", i.quote()),
478+
msg: format!("invalid -{option} argument {}", i.quote()),
479479
})
480480
};
481481
matches
@@ -771,13 +771,23 @@ fn build_options(
771771
})
772772
});
773773
let start_column_option = match res {
774+
Some(Ok(0)) => {
775+
return Err(PrError::EncounteredErrors {
776+
msg: "invalid --column argument '0'".to_string(),
777+
});
778+
}
774779
Some(res) => Some(res?),
775780
None => None,
776781
};
777782

778783
// --column has more priority than -column
779784

780785
let column_option_value = match parse_usize(matches, options::COLUMN) {
786+
Some(Ok(0)) => {
787+
return Err(PrError::EncounteredErrors {
788+
msg: "invalid --column argument '0'".to_string(),
789+
});
790+
}
781791
Some(res) => Some(res?),
782792
None => start_column_option,
783793
};

tests/by-util/test_pr.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,3 +873,19 @@ fn test_expand_tab_does_not_consume_next_argument() {
873873
new_ucmd!().args(&["-ea", test_file_path]).succeeds();
874874
new_ucmd!().args(&["-ea1", test_file_path]).succeeds();
875875
}
876+
877+
#[test]
878+
fn test_zero_columns() {
879+
new_ucmd!()
880+
.arg("--column=0")
881+
.fails_with_code(1)
882+
.stderr_contains("pr: invalid --column argument '0'");
883+
}
884+
885+
#[test]
886+
fn test_zero_columns_shortcut() {
887+
new_ucmd!()
888+
.arg("-0")
889+
.fails_with_code(1)
890+
.stderr_contains("pr: invalid --column argument '0'");
891+
}

0 commit comments

Comments
 (0)