@@ -74,6 +74,10 @@ impl EnvKey {
7474// [4] https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringordinal
7575impl Ord for EnvKey {
7676 fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
77+ if !c:: CompareStringOrdinal :: option ( ) . is_some ( ) {
78+ return self . os_string . cmp ( & other. os_string ) ;
79+ }
80+
7781 unsafe {
7882 let result = c:: CompareStringOrdinal (
7983 self . utf16 . as_ptr ( ) ,
@@ -124,7 +128,12 @@ impl PartialEq<str> for EnvKey {
124128// Environment variable keys should preserve their original case even though
125129// they are compared using a caseless string mapping.
126130impl From < OsString > for EnvKey {
127- fn from ( k : OsString ) -> Self {
131+ fn from ( mut k : OsString ) -> Self {
132+ if !c:: CompareStringOrdinal :: option ( ) . is_some ( ) {
133+ k. make_ascii_uppercase ( ) ;
134+ return EnvKey { utf16 : Vec :: new ( ) , os_string : k } ;
135+ }
136+
128137 EnvKey { utf16 : k. encode_wide ( ) . collect ( ) , os_string : k }
129138 }
130139}
@@ -857,8 +866,12 @@ fn make_envp(maybe_env: Option<BTreeMap<EnvKey, OsString>>) -> io::Result<(*mut
857866 }
858867
859868 for ( k, v) in env {
860- ensure_no_nuls ( k. os_string ) ?;
861- blk. extend ( k. utf16 ) ;
869+ if !c:: CompareStringOrdinal :: option ( ) . is_some ( ) {
870+ blk. extend ( ensure_no_nuls ( k. os_string ) ?. encode_wide ( ) ) ;
871+ } else {
872+ ensure_no_nuls ( k. os_string ) ?;
873+ blk. extend ( k. utf16 ) ;
874+ }
862875 blk. push ( '=' as u16 ) ;
863876 blk. extend ( ensure_no_nuls ( v) ?. encode_wide ( ) ) ;
864877 blk. push ( 0 ) ;
0 commit comments