Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear environment for child Commands #12901

Merged
merged 3 commits into from
May 19, 2024
Merged

Conversation

IanManske
Copy link
Member

Description

There is a bug when hide-env is used on environment variables that were present at shell startup. Namely, child processes still inherit the hidden environment variable. This PR fixes #12900, fixes #11495, and fixes #7937.

Tests + Formatting

Added a test.

@IanManske IanManske added the pr:bugfix This PR fixes some bug label May 18, 2024
@@ -537,6 +537,7 @@ impl ExternalCommand {
.to_string();

let mut process = std::process::Command::new(head);
process.env_clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can completely nuke the environment on Windows:

Are we modifying the env later before spawning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we modifying the env later before spawning?

Yep, of course. So if the necessary windows environment variables are present in nushell's emulated env, then the child process will get them. But if a user uses hide-env on one of those special env vars then 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this method is pub maybe worth documenting. The only outside use in exec seems to also properly set the environment.

@IanManske IanManske merged commit 474293b into nushell:main May 19, 2024
15 checks passed
@hustcer hustcer added this to the v0.94.0 milestone May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:bugfix This PR fixes some bug
Projects
None yet
3 participants