diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 9944dfd22b..4895ab537a 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -124,6 +124,8 @@ pub fn base_app(about: String, usage: String) -> Command { .short('w') .long(options::WRAP) .value_name("COLS") + // GNU takes the token after -w as the wrap size even when it starts with '-'. + .allow_hyphen_values(true) .help(translate!("base-common-help-wrap", "default" => WRAP_DEFAULT)) .overrides_with(options::WRAP), ) diff --git a/tests/by-util/test_base64.rs b/tests/by-util/test_base64.rs index 9dfc5b3000..558c171a95 100644 --- a/tests/by-util/test_base64.rs +++ b/tests/by-util/test_base64.rs @@ -219,6 +219,20 @@ fn test_wrap_bad_arg() { } } +#[test] +fn test_wrap_negative_arg() { + // GNU consumes the token after -w as the wrap size even when it begins + // with '-', reporting it as an invalid wrap size rather than an unknown + // option. + for arg in ["-5", "-d"] { + new_ucmd!() + .arg("-w") + .arg(arg) + .fails() + .stderr_only(format!("base64: invalid wrap size: '{arg}'\n")); + } +} + #[test] fn test_base64_extra_operand() { // Expect a failure when multiple files are specified.