mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
pr: reject a non-positive expand-tab width (-e0)
`pr -e0` on input containing a tab aborted with a remainder-by-zero panic (`chunk.len() % expand_options.width` in `apply_expand_tab`). The `-e[char][width]` parser accepted a width of `0` — and a negative width via e.g. `-eX-5` — without validation, so the zero/negative reached the chunk arithmetic. Reject `width <= 0` while parsing `-e`, emitting the same invalid-argument error GNU produces (`pr: '-e' extra characters or invalid number in the argument: '0'`, exit 1) instead of crashing.
This commit is contained in:
@@ -889,3 +889,16 @@ fn test_zero_columns_shortcut() {
|
||||
.fails_with_code(1)
|
||||
.stderr_contains("pr: invalid --column argument '0'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_expand_tab_width() {
|
||||
let expected = "pr: '-e' extra characters or invalid number in the argument: ‘0’\nTry 'pr --help' for more information.\n";
|
||||
new_ucmd!()
|
||||
.arg("-e0")
|
||||
.fails_with_code(1)
|
||||
.stderr_only(expected);
|
||||
new_ucmd!()
|
||||
.arg("-eX0")
|
||||
.fails_with_code(1)
|
||||
.stderr_only(expected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user