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:
weili
2026-06-05 11:19:08 +02:00
committed by Daniel Hofstetter
parent e63cc0c260
commit abcdcdca53
2 changed files with 50 additions and 16 deletions
+13
View File
@@ -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);
}