Skip to content
Merged
12 changes: 11 additions & 1 deletion src/uu/pr/src/pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a future pr, please use the translate!() macro for translation

})
};
matches
Expand Down Expand Up @@ -771,13 +771,23 @@ fn build_options(
})
});
let start_column_option = match res {
Some(Ok(0)) => {
return Err(PrError::EncounteredErrors {
msg: "invalid --column argument '0'".to_string(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

});
}
Some(res) => Some(res?),
None => None,
};

// --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(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

});
}
Some(res) => Some(res?),
None => start_column_option,
};
Expand Down
16 changes: 16 additions & 0 deletions tests/by-util/test_pr.rs
Comment thread
Devel08 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
}
Loading