From d40afa987193deaddebc8a1917b03d54fcb53fa2 Mon Sep 17 00:00:00 2001 From: Devel Date: Thu, 11 Jun 2026 16:03:43 +0300 Subject: [PATCH 1/6] return error whenever -w is zero --- src/uu/pr/src/pr.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 73b8706db4..3af3952dfa 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -787,7 +787,13 @@ fn build_options( let column_width = parse_usize(matches, options::COLUMN_WIDTH).unwrap_or(Ok(default_column_width))?; - + + if column_width == 0 { + return Err(PrError::EncounteredErrors { + msg: "invalid --width argument '0'".to_string(), + }); + } + let page_width = if matches.get_flag(options::JOIN_LINES) { None } else { From e8c8ad5dba331acc82511ed9f2ace12b2474413c Mon Sep 17 00:00:00 2001 From: Devel Date: Thu, 11 Jun 2026 16:05:35 +0300 Subject: [PATCH 2/6] pr: add test_zero_column_width --- tests/by-util/test_pr.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 16a4032a7f..01895cfce9 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -930,3 +930,11 @@ fn test_zero_expand_tab_width() { .fails_with_code(1) .stderr_only(expected); } + +#[test] +fn test_zero_column_width() { + new_ucmd!() + .args(&["-w", "0"]) + .fails_with_code(1) + .stderr_is("pr: invalid --width argument '0'\n"); +} From d1998c28823ef22decb89781cc9286276c851804 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 13:07:44 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/uu/pr/src/pr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index 3af3952dfa..efbf81b76f 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -787,13 +787,13 @@ fn build_options( let column_width = parse_usize(matches, options::COLUMN_WIDTH).unwrap_or(Ok(default_column_width))?; - + if column_width == 0 { return Err(PrError::EncounteredErrors { msg: "invalid --width argument '0'".to_string(), }); } - + let page_width = if matches.get_flag(options::JOIN_LINES) { None } else { From 1ed684e8a32ca3c1b18f90f4d58d60be3a3a2fc9 Mon Sep 17 00:00:00 2001 From: Devel Date: Thu, 11 Jun 2026 17:16:45 +0300 Subject: [PATCH 4/6] add page width check too --- src/uu/pr/src/pr.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index efbf81b76f..d270782cba 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -803,6 +803,12 @@ fn build_options( } }; + if page_width == Some(0) { + return Err(PrError::EncounteredErrors { + msg: "invalid --page-width argument '0'".to_string(), + }); + } + let re_col = Regex::new(r"\s*-(\d+)\s*").unwrap(); let res = re_col.captures(free_args).map(|i| { From 330919422ad92f0bfedd89d6bc526b554b3707ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Jun 2026 14:17:00 +0000 Subject: [PATCH 5/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/uu/pr/src/pr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index d270782cba..29acf48dfa 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -808,7 +808,7 @@ fn build_options( msg: "invalid --page-width argument '0'".to_string(), }); } - + let re_col = Regex::new(r"\s*-(\d+)\s*").unwrap(); let res = re_col.captures(free_args).map(|i| { From 5a4d17eef1426ba6a5066a6e150eeb820720a564 Mon Sep 17 00:00:00 2001 From: Devel Date: Thu, 11 Jun 2026 17:17:28 +0300 Subject: [PATCH 6/6] add test_zero_page_width --- tests/by-util/test_pr.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 01895cfce9..b7d500e6af 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -938,3 +938,11 @@ fn test_zero_column_width() { .fails_with_code(1) .stderr_is("pr: invalid --width argument '0'\n"); } + +#[test] +fn test_zero_page_width() { + new_ucmd!() + .args(&["-W", "0"]) + .fails_with_code(1) + .stderr_is("pr: invalid --page-width argument '0'\n"); +}