gnucompability(fold): uutils fold accept width 0 but gnu fold rejects it (#12744)

This commit is contained in:
Devel
2026-06-09 22:12:54 +02:00
committed by GitHub
parent 1a39966ef0
commit 47f549a8fa
2 changed files with 24 additions and 6 deletions
+15 -6
View File
@@ -64,12 +64,21 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};
let width = match poss_width {
Some(inp_width) => inp_width.parse::<usize>().map_err(|e| {
USimpleError::new(
1,
translate!("fold-error-illegal-width", "width" => inp_width.quote(), "error" => e),
)
})?,
Some(inp_width) => match inp_width.parse::<usize>() {
Ok(0) => {
return Err(USimpleError::new(
1,
translate!("fold-error-illegal-width", "width" => inp_width.quote()),
));
}
Ok(parsed_width) => parsed_width,
Err(e) => {
return Err(USimpleError::new(
1,
translate!("fold-error-illegal-width", "width" => inp_width.quote(), "error" => e),
));
}
},
None => 80,
};
+9
View File
@@ -1033,3 +1033,12 @@ fn test_character_mode_special_chars() {
.stdout_is(expected);
}
}
#[test]
fn test_width_zero() {
new_ucmd!()
.arg("-w")
.arg("0")
.fails_with_code(1)
.stderr_is("fold: illegal width value\n");
}