-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Windows std::env::vars() uppercases environment variables #85242
Comments
I don't think this is related to reading environment variables, but is related to process spawning. If you are spawning a process from a Rust program, then they will be uppercased. But if the Rust program is spawned from something else (like PowerShell), then the env keys should be case-preserved. The issue is here. This was originally added in #17249 to fix #16937. I personally don't think that issue is all that important that all environment keys should be forced to be uppercase. However, if there is a desire to fix both issues, then there would need to be a case-insensitive map (maybe just keep a separate set of uppercased keys?). |
@ehuss thanks for the pointer. For our case, Nushell should be able to spawn processes and keep the environment as expected rather than uppercasing. This allows Nushell to work just as PowerShell spawning a program. As best as I can tell, it's the lookup of a single variable that should be case-insensitive and that listing of variables should maintain the case they had, though I'm far from an expert here. |
Hm, the current code does look wrong. Windows environment variables are compared case-insensitive but when set they keep the same case. The simplest improvement here would be remove the However, note that Windows uses Unicode casing, not just ASCII. There is a Windows function for comparing but using it for |
I tried this code:
I expected to see this happen: a case-sensitive list of environment variables and values, matching the output of
Environment.GetEnvironmentVariables
from C# and .NET and the output ofGet-ChildItem Env:
from PowerShell.It seems we should align the
std::env::vars()
output to match the modern APIs for Windows that Microsoft provides.Instead, this happened:
std::env::vars()
returns all environment variable names in all uppercase.Rust via
std::env::vars()
:C# via
Environment.GetEnvironmentVariables
:Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: