File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
src/System.Management.Automation/namespaces
test/powershell/Modules/Microsoft.PowerShell.Management Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -198,7 +198,15 @@ internal override IDictionary GetSessionStateTable()
198
198
IDictionary environmentTable = Environment . GetEnvironmentVariables ( ) ;
199
199
foreach ( DictionaryEntry entry in environmentTable )
200
200
{
201
- providerTable . Add ( ( string ) entry . Key , entry ) ;
201
+ // Windows only: duplicate key (variable name that differs only in case)
202
+ // NOTE: Even though this shouldn't happen, it can, e.g. when npm
203
+ // creates duplicate environment variables that differ only in case -
204
+ // see https://github.com/PowerShell/PowerShell/issues/6305.
205
+ // However, because retrieval *by name* later is invariably
206
+ // case-Insensitive, in effect only a *single* variable exists.
207
+ // We simply ask Environment.GetEnvironmentVariable() which value is
208
+ // the effective one, and use that.
209
+ providerTable . TryAdd ( ( string ) entry . Key , entry ) ;
202
210
}
203
211
204
212
return providerTable ;
Original file line number Diff line number Diff line change @@ -116,4 +116,30 @@ Describe "Get-Item" -Tags "CI" {
116
116
${result} | Should - BeOfType " Microsoft.Win32.RegistryKey"
117
117
}
118
118
}
119
+
120
+ Context " Environment provider" - tag " CI" {
121
+ BeforeAll {
122
+ $env: testvar = " b"
123
+ $env: testVar = " a"
124
+ }
125
+
126
+ AfterAll {
127
+ Clear-Item - Path env:testvar - ErrorAction SilentlyContinue
128
+ Clear-Item - Path env:testVar - ErrorAction SilentlyContinue
129
+ }
130
+
131
+ It " get-item testVar" {
132
+ (get-item env:\testVar).Value | Should - BeExactly " a"
133
+ }
134
+
135
+ It " get-item is case-sensitive/insensitive as appropriate" {
136
+ $expectedValue = " b"
137
+ if ($IsWindows )
138
+ {
139
+ $expectedValue = " a"
140
+ }
141
+
142
+ (get-item env:\testvar).Value | Should - BeExactly $expectedValue
143
+ }
144
+ }
119
145
}
You can’t perform that action at this time.
0 commit comments