Skip to content

fix hide-env, refactor: rename remove_env_var to hide_env_var for clarity and update related logic - #18170

Merged
fdncred merged 6 commits into
nushell:mainfrom
fdncred:fix_hide_env_20260506
May 13, 2026
Merged

fdncred merged 6 commits into
nushell:mainfrom
fdncred:fix_hide_env_20260506

Conversation

@fdncred

@fdncred fdncred commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix hide-env not hiding variables after stack-level override

$env.AAAA = "aaaa"; $env.AAAA = ""; hide-env AAAA failed to hide AAAA. After the empty-string assignment, remove_env_var would remove the stack entry and return true — but never mark the engine-state baseline as hidden, so $env.AAAA was still accessible.

Add a Stack::hide_env_var method with full hiding semantics: removes the variable from the stack and marks the engine-state baseline as hidden in env_hidden. The existing remove_env_var is preserved for callers that only need to clean up a stack-level value (e.g. FILE_PWD).

User-facing changes (Release notes)

Fixes the issue where $env.AAAA = "aaaa"; $env.AAAA = ""; hide-env AAAA failed to hide AAAA. After the empty-string assignment.

Additional notes

closes #18169

@Bahex
Bahex force-pushed the fix_hide_env_20260506 branch from f066e10 to eef55a4 Compare May 7, 2026 12:12
@Bahex
Bahex force-pushed the fix_hide_env_20260506 branch from ce34843 to dc87fdd Compare May 7, 2026 12:20
@fdncred

fdncred commented May 7, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm fine with these changes but I think it makes the code harder to understand, other than the tests.

These changes kind of stand out now since the rest of the file is for based.

@Bahex

Bahex commented May 7, 2026

Copy link
Copy Markdown
Member

@fdncred I've amended the first commit (just changed the order of functions) to make its diff easier to read.

Aside from that, some of the existing tests weren't actually testing whether they got the error they were expecting.

Comment thread tests/repl/test_hiding.rs Resolved
@fdncred

fdncred commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@Bahex I pushed a "fix" for the hide-env twice thing. Hopefully the CI goes green. Let me know if you have more input on the changes.

@fdncred

fdncred commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Thinking more about this example:

$env.myfoosymbol = "myfoosymbol"
do {
    hide-env myfoosymbol
    $env.myfoosymbol
}

I think the outer scoped env var should be hidden. People don't really use do to only change the inner scope (I don't think).

@fdncred

fdncred commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

Let's see if this CI goes green. I really don't care for the solution but I couldn't figure out other ways to accomplish this since it involves hiding envs in scope.

@fdncred
fdncred merged commit 39d28ef into nushell:main May 13, 2026
17 checks passed
@fdncred
fdncred deleted the fix_hide_env_20260506 branch May 13, 2026 12:48
@github-actions github-actions Bot added this to the v0.113.0 milestone May 13, 2026
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inability to fully hide XDG environment variables in config files

2 participants