Skip to content

Commit ae3756b

Browse files
committed
seq: Do not allow -w and -f to be specified at the same time
Fixes #7466.
1 parent d6cf38f commit ae3756b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/uu/seq/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pub enum SeqError {
2828
/// No arguments were passed to this function, 1 or more is required
2929
#[error("missing operand")]
3030
NoArguments,
31+
32+
/// Both a format and equal width where passed to seq
33+
#[error("format string may not be specified when printing equal width strings")]
34+
FormatAndEqualWidth,
3135
}
3236

3337
fn parse_error_type(e: &ParseNumberError) -> &'static str {

src/uu/seq/src/seq.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
114114
format: matches.get_one::<String>(OPT_FORMAT).map(|s| s.as_str()),
115115
};
116116

117+
if options.equal_width && options.format.is_some() {
118+
return Err(SeqError::FormatAndEqualWidth.into());
119+
}
120+
117121
let first = if numbers.len() > 1 {
118122
match numbers[0].parse() {
119123
Ok(num) => num,

tests/by-util/test_seq.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ fn test_no_args() {
1919
.stderr_contains("missing operand");
2020
}
2121

22+
#[test]
23+
fn test_format_and_equal_width() {
24+
new_ucmd!()
25+
.args(&["-w", "-f", "%f", "1"])
26+
.fails_with_code(1)
27+
.stderr_contains("format string may not be specified");
28+
}
29+
2230
#[test]
2331
fn test_hex_rejects_sign_after_identifier() {
2432
new_ucmd!()

0 commit comments

Comments
 (0)