-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Config env snapshot doesn't handle case-insensitive env vars correctly on windows #11814
Comments
Hi, thanks for the detailed explanation. Sorry about this, I didn't know that env vars are case-insensitive on Windows until now. The |
Hm, I don't think that will work perfectly since I believe Windows does case conversion a little differently from how Rust does it (and it depends on the version of Windows), but I think for our purposes, |
Btw, I wrote a detailed comment on a similar issue elsewhere. |
Handle case mismatches when looking up env vars in the Config snapshot ### What does this PR try to resolve? Fixes #11814. Windows environment variables are case-insensitive, which causes problems when looking them up in the `Config` env snapshot. This PR adds another member (`case_insensitive_env`) in `Config` that maps upper-cased keys to their original values in the env (for example, `"PATH" => "Path"`). If lookup in `self.env` fails, this PR converts the key to upper case and looks it up in `self.case_insensitive_env` to obtain the correct key name if it exists (on Windows only). ### How should we test and review this PR? Please see the new tests in `testsuite/config.rs` and `testsuite/cargo_command.rs`. ### Additional information Currently, this uses `str::to_uppercase` to uppercase the keys. This requires key to be valid UTF-8, and may disagree with how the OS uppercases things (see the link in [this comment](#11814 (comment)) for details).
…=ehuss Handle case mismatches when looking up env vars in the Config snapshot ### What does this PR try to resolve? Fixes rust-lang#11814. Windows environment variables are case-insensitive, which causes problems when looking them up in the `Config` env snapshot. This PR adds another member (`case_insensitive_env`) in `Config` that maps upper-cased keys to their original values in the env (for example, `"PATH" => "Path"`). If lookup in `self.env` fails, this PR converts the key to upper case and looks it up in `self.case_insensitive_env` to obtain the correct key name if it exists (on Windows only). ### How should we test and review this PR? Please see the new tests in `testsuite/config.rs` and `testsuite/cargo_command.rs`. ### Additional information Currently, this uses `str::to_uppercase` to uppercase the keys. This requires key to be valid UTF-8, and may disagree with how the OS uppercases things (see the link in [this comment](rust-lang#11814 (comment)) for details).
Problem
Some recent changes introduce snapshotting of env variables:
cargo/src/cargo/util/config/mod.rs
Lines 209 to 210 in a5d47a7
e. g. this PR #11727 by @kylematsuda
That introduces a little bug on windows where env vars are case-insensitive.
env::var_os
would handle that correctly, butconfig.get_env_os
does a HashMap lookup which is case-sensitive.e. g. the mentioned PR breaks the lookup of cargo subcommands on windows (where the env var is called
Path
instead ofPATH
).Steps
<subcommand>
Workaround:
This changes the casing of the env variable.
Possible Solution(s)
Wrap the keys in the env snapshot HashMap with some case-insenstive NewType struct.
Notes
No response
Version
The text was updated successfully, but these errors were encountered: