Skip to content

Commit 3c8633a

Browse files
committed
change set_env to update case_insensitive_env and normalized_env (needed for tests)
1 parent 0255c30 commit 3c8633a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/cargo/util/config/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub struct Config {
205205
/// (relevant on Windows, where environment variables are case-insensitive).
206206
case_insensitive_env: HashMap<OsString, OsString>,
207207
/// Environment variables converted to uppercase and with "-" replaced by "_"
208-
/// (the format expected by Cargo).
208+
/// (the format expected by Cargo). This only contains entries that were valid UTF-8.
209209
normalized_env: HashMap<String, String>,
210210
/// Tracks which sources have been updated to avoid multiple updates.
211211
updated_sources: LazyCell<RefCell<HashSet<SourceId>>>,
@@ -741,6 +741,15 @@ impl Config {
741741
/// Helper primarily for testing.
742742
pub fn set_env(&mut self, env: HashMap<String, String>) {
743743
self.env = env.into_iter().map(|(k, v)| (k.into(), v.into())).collect();
744+
self.case_insensitive_env = self
745+
.env
746+
.keys()
747+
.map(|k| (k.to_ascii_uppercase(), k.to_owned()))
748+
.collect();
749+
self.normalized_env = self
750+
.env()
751+
.map(|(k, _)| (k.to_uppercase().replace("-", "_"), k.to_owned()))
752+
.collect();
744753
}
745754

746755
/// Returns all environment variables as an iterator, filtering out entries

0 commit comments

Comments
 (0)