mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
gnucompability(fold): uutils fold accept width 0 but gnu fold rejects it (#12744)
This commit is contained in:
+15
-6
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user