@@ -74,6 +74,10 @@ impl EnvKey {
74
74
// [4] https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringordinal
75
75
impl Ord for EnvKey {
76
76
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
+
77
81
unsafe {
78
82
let result = c:: CompareStringOrdinal (
79
83
self . utf16 . as_ptr ( ) ,
@@ -124,7 +128,12 @@ impl PartialEq<str> for EnvKey {
124
128
// Environment variable keys should preserve their original case even though
125
129
// they are compared using a caseless string mapping.
126
130
impl 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
+
128
137
EnvKey { utf16 : k. encode_wide ( ) . collect ( ) , os_string : k }
129
138
}
130
139
}
@@ -857,8 +866,12 @@ fn make_envp(maybe_env: Option<BTreeMap<EnvKey, OsString>>) -> io::Result<(*mut
857
866
}
858
867
859
868
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
+ }
862
875
blk. push ( '=' as u16 ) ;
863
876
blk. extend ( ensure_no_nuls ( v) ?. encode_wide ( ) ) ;
864
877
blk. push ( 0 ) ;
0 commit comments