@@ -203,9 +203,10 @@ pub struct Config {
203
203
env : HashMap < OsString , OsString > ,
204
204
/// Environment variables converted to uppercase to check for case mismatch
205
205
/// (relevant on Windows, where environment variables are case-insensitive).
206
- case_insensitive_env : HashMap < OsString , OsString > ,
206
+ case_insensitive_env : HashMap < String , String > ,
207
207
/// Environment variables converted to uppercase and with "-" replaced by "_"
208
- /// (the format expected by Cargo). This only contains entries that were valid UTF-8.
208
+ /// (the format expected by Cargo). This only contains entries where the key and variable are
209
+ /// both valid UTF-8.
209
210
normalized_env : HashMap < String , String > ,
210
211
/// Tracks which sources have been updated to avoid multiple updates.
211
212
updated_sources : LazyCell < RefCell < HashSet < SourceId > > > ,
@@ -268,7 +269,8 @@ impl Config {
268
269
269
270
let case_insensitive_env: HashMap < _ , _ > = env
270
271
. keys ( )
271
- . map ( |k| ( k. to_ascii_uppercase ( ) , k. to_owned ( ) ) )
272
+ . filter_map ( |k| k. to_str ( ) )
273
+ . map ( |k| ( k. to_uppercase ( ) , k. to_owned ( ) ) )
272
274
. collect ( ) ;
273
275
274
276
let normalized_env = env
@@ -742,9 +744,8 @@ impl Config {
742
744
pub fn set_env ( & mut self , env : HashMap < String , String > ) {
743
745
self . env = env. into_iter ( ) . map ( |( k, v) | ( k. into ( ) , v. into ( ) ) ) . collect ( ) ;
744
746
self . case_insensitive_env = self
745
- . env
746
- . keys ( )
747
- . map ( |k| ( k. to_ascii_uppercase ( ) , k. to_owned ( ) ) )
747
+ . env_keys ( )
748
+ . map ( |k| ( k. to_uppercase ( ) , k. to_owned ( ) ) )
748
749
. collect ( ) ;
749
750
self . normalized_env = self
750
751
. env ( )
@@ -820,11 +821,12 @@ impl Config {
820
821
821
822
/// Wrapper for `self.env.get` when `key` should be case-insensitive.
822
823
/// This is relevant on Windows, where environment variables are case-insensitive.
824
+ /// Note that this only works on keys that are valid UTF-8.
823
825
fn get_env_case_insensitive ( & self , key : impl AsRef < OsStr > ) -> Option < & OsString > {
824
- let upper_case_key = key. as_ref ( ) . to_ascii_uppercase ( ) ;
826
+ let upper_case_key = key. as_ref ( ) . to_str ( ) ? . to_uppercase ( ) ;
825
827
// `self.case_insensitive_env` holds pairs like `("PATH", "Path")`
826
828
// or `("MY-VAR", "my-var")`.
827
- let env_key = self . case_insensitive_env . get ( & upper_case_key) ?;
829
+ let env_key: & OsStr = self . case_insensitive_env . get ( & upper_case_key) ?. as_ref ( ) ;
828
830
self . env . get ( env_key)
829
831
}
830
832
0 commit comments