mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 06:42:42 +00:00
Merge pull request #4113 from sylvestre/var-env
Weird env variable names should trigger an error.
This commit is contained in:
commit
526cbae9ce
2 changed files with 17 additions and 3 deletions
|
@ -40,16 +40,21 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
let mut not_found = false;
|
||||
let mut error_found = false;
|
||||
for env_var in variables {
|
||||
// we silently ignore a=b as variable but we trigger an error
|
||||
if env_var.contains('=') {
|
||||
error_found = true;
|
||||
continue;
|
||||
}
|
||||
if let Ok(var) = env::var(env_var) {
|
||||
print!("{}{}", var, separator);
|
||||
} else {
|
||||
not_found = true;
|
||||
error_found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if not_found {
|
||||
if error_found {
|
||||
Err(1.into())
|
||||
} else {
|
||||
Ok(())
|
||||
|
|
|
@ -28,3 +28,12 @@ fn test_get_var() {
|
|||
assert!(!result.stdout_str().is_empty());
|
||||
assert_eq!(result.stdout_str().trim(), "VALUE");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_equal_var() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
// tested by gnu/tests/misc/printenv.sh
|
||||
let result = scene.ucmd().env("a=b", "c").arg("a=b").fails();
|
||||
|
||||
assert!(result.stdout_str().is_empty());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue