mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
env: don't allow '=' with -u (#7008)
* Added error handling to ensure '=' after -u returns 125 as '=' is not allowed * Added tests for disallow = on short options * Added error handling to ensure '=' after -u returns 125 as '=' is not allowed * Added tests for disallow = on short options * Disallow only short unset option from having '=' as its starting character * Remove needless tests and update function name for clarity
This commit is contained in:
parent
d81d893964
commit
646fc394f6
2 changed files with 36 additions and 0 deletions
13
src/uu/env/src/env.rs
vendored
13
src/uu/env/src/env.rs
vendored
|
@ -370,6 +370,19 @@ impl EnvAppData {
|
||||||
self.had_string_argument = true;
|
self.had_string_argument = true;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
let arg_str = arg.to_string_lossy();
|
||||||
|
|
||||||
|
// Short unset option (-u) is not allowed to contain '='
|
||||||
|
if arg_str.contains('=')
|
||||||
|
&& arg_str.starts_with("-u")
|
||||||
|
&& !arg_str.starts_with("--")
|
||||||
|
{
|
||||||
|
return Err(USimpleError::new(
|
||||||
|
125,
|
||||||
|
format!("cannot unset '{}': Invalid argument", &arg_str[2..]),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
all_args.push(arg.clone());
|
all_args.push(arg.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -882,6 +882,29 @@ fn test_env_arg_ignore_signal_empty() {
|
||||||
.no_stderr()
|
.no_stderr()
|
||||||
.stdout_contains("hello");
|
.stdout_contains("hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn disallow_equals_sign_on_short_unset_option() {
|
||||||
|
let ts = TestScenario::new(util_name!());
|
||||||
|
|
||||||
|
ts.ucmd()
|
||||||
|
.arg("-u=")
|
||||||
|
.fails()
|
||||||
|
.code_is(125)
|
||||||
|
.stderr_contains("env: cannot unset '=': Invalid argument");
|
||||||
|
ts.ucmd()
|
||||||
|
.arg("-u=A1B2C3")
|
||||||
|
.fails()
|
||||||
|
.code_is(125)
|
||||||
|
.stderr_contains("env: cannot unset '=A1B2C3': Invalid argument");
|
||||||
|
ts.ucmd().arg("--split-string=A1B=2C3=").succeeds();
|
||||||
|
ts.ucmd()
|
||||||
|
.arg("--unset=")
|
||||||
|
.fails()
|
||||||
|
.code_is(125)
|
||||||
|
.stderr_contains("env: cannot unset '': Invalid argument");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests_split_iterator {
|
mod tests_split_iterator {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue