coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Throw error if unset argument starts with '=' for env command

Open Carbrex opened this issue 10 months ago • 16 comments

#6165 #6166

Output

Before:

$ cargo run env | grep ZZZ 
ZZZ=zzz
$ cargo run env -u=ZZZ | grep ZZZ

(No output because ZZZ was unset)

After:

$ cargo run env | grep ZZZ
ZZZ=zzz
$ cargo run env -u=ZZZ | grep ZZZ
env: cannot unset '=ZZZ': Invalid argument
Try 'target/debug/coreutils env --help' for more information.

Tests:

Before:

$ cargo test test_env_with_gnu_reference_unset_invalid_variables

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 70 filtered out; finished in 0.00s


running 1 test
test test_env::test_env_with_gnu_reference_unset_invalid_variables ... FAILED

failures:

---- test_env::test_env_with_gnu_reference_unset_invalid_variables stdout ----
run: /home/geet/debian-gsoc/coreutils/target/debug/coreutils env -u=2EKt
thread 'test_env::test_env_with_gnu_reference_unset_invalid_variables' panicked at tests/by-util/test_env.rs:578:10:
Command was expected to fail.
stdout = LC_ALL=C
TZ=UTC

 stderr = 
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    test_env::test_env_with_gnu_reference_unset_invalid_variables

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 2875 filtered out; finished in 0.00s

After:

$ cargo test test_env_with_gnu_reference_unset_invalid_variables

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 70 filtered out; finished in 0.00s


running 1 test
test test_env::test_env_with_gnu_reference_unset_invalid_variables ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2875 filtered out; finished in 0.01s

Carbrex avatar Apr 01 '24 15:04 Carbrex

Hi again! I made a mistake and merged your other PR a bit too quickly, which is why the other maintainers had to do a force-push. Sorry ^^'

I'd be happy to help you sort out this mess in case you get stuck with git rebase. I'm available to chat in the uutils Discord chat.

BenWiederhake avatar Apr 01 '24 15:04 BenWiederhake

Hi again! I made a mistake and merged your other PR a bit too quickly, which is why the other maintainers had to do a force-push. Sorry ^^'

I'd be happy to help you sort out this mess in case you get stuck with git rebase. I'm available to chat in the uutils Discord chat.

Thanks for your help I will try to fix it and if I fail I will certainly ask you on discord.

Carbrex avatar Apr 01 '24 15:04 Carbrex

Please rebase your work Thanks

sylvestre avatar Apr 01 '24 15:04 sylvestre

Thanks for your patience! Its ready to be reviewed now. I was not able to remove this Add test for ignoring time-style if time not defined commit using rebase as it shows some error.

Carbrex avatar Apr 01 '24 15:04 Carbrex

please fix the lint

sylvestre avatar Apr 01 '24 17:04 sylvestre

please fix the lint

I think all the lint tests have passed, haven't they?

Carbrex avatar Apr 01 '24 17:04 Carbrex

Seems that it needs more work: With this PR:

./target/debug/coreutils env -i -0 -u=kQ4dALb1 A=0d CZj=lYr
env: cannot unset '=kQ4dALb1': Invalid argument

With GNU:

$ /usr/bin/env -i -0 -u=kQ4dALb1 A=0d CZj=lYr
A=0dCZj=lYr%      

sylvestre avatar Apr 01 '24 18:04 sylvestre

Seems that it needs more work: With this PR:

./target/debug/coreutils env -i -0 -u=kQ4dALb1 A=0d CZj=lYr
env: cannot unset '=kQ4dALb1': Invalid argument

With GNU:

$ /usr/bin/env -i -0 -u=kQ4dALb1 A=0d CZj=lYr
A=0dCZj=lYr%      

Ok thanks I will look into it.

Carbrex avatar Apr 01 '24 19:04 Carbrex

These are some other results with GNU that don't match:

$ env -0 -u=kQ4dALb1 - A=0d CZj=lYr
A=0dCZj=lYr
$ env -0 -u=kQ4dALb1 - A=0d CZj=lYr 
A=0dCZj=lYr 
$ env -u=kQ4dALb1 - A=0d CZj=lYr 
A=0d
CZj=lYr
$ env -i -u=kQ4dALb1  A=0d CZj=lYr
A=0d
CZj=lYr

Carbrex avatar Apr 01 '24 19:04 Carbrex

I am converting this to a draft pr until I fix these.

Carbrex avatar Apr 01 '24 19:04 Carbrex

Some more deviations from gnu are

$ env D=ddsa - A=0d CZj=lYr  
env: ‘-’: No such file or directory
                                                                                       
$ cargo run env D=ddsa - A=0d CZj=lYr 
D=ddsa
A=0d
CZj=lYr

$ env -- -u=kQ4dALb1 A=0d  CZj=lYr      
(Prints all environment variables)

After some testing I have found that gnu works if there is -i or '-' before or after '-u=adsfas'. Also, when there is '--' before '-u=adfs'. Some help would be appreciated on what should I do.

Carbrex avatar Apr 02 '24 11:04 Carbrex

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/timeout/timeout is no longer failing!

github-actions[bot] avatar May 21 '24 11:05 github-actions[bot]

is it ready to be reviewed? Thanks

sylvestre avatar Jun 04 '24 21:06 sylvestre

No, sorry it isn't ready for review. This pr wont work because of so many weird behavior by gnu as mentioned in my previous comments. But I guess the tests might be useful. I might write some more tests if needed?

Carbrex avatar Jun 04 '24 22:06 Carbrex

Sure sounds good :)

sylvestre avatar Jun 05 '24 05:06 sylvestre

I think I have added enough tests.

Carbrex avatar Jun 05 '24 08:06 Carbrex