Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,15 @@ internal override IDictionary GetSessionStateTable()
IDictionary environmentTable = Environment.GetEnvironmentVariables();
foreach (DictionaryEntry entry in environmentTable)
{
providerTable.Add((string)entry.Key, entry);
// Windows only: duplicate key (variable name that differs only in case)
// NOTE: Even though this shouldn't happen, it can, e.g. when npm
// creates duplicate environment variables that differ only in case -
// see https://github.com/PowerShell/PowerShell/issues/6305.
// However, because retrieval *by name* later is invariably
// case-Insensitive, in effect only a *single* variable exists.
// We simply ask Environment.GetEnvironmentVariable() which value is
// the effective one, and use that.
providerTable.TryAdd((string)entry.Key, entry);
}

return providerTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,30 @@ Describe "Get-Item" -Tags "CI" {
${result} | Should BeOfType "Microsoft.Win32.RegistryKey"
}
}

Context "Environment provider" -tag "CI" {
BeforeAll {
$env:testvar="b"
$env:testVar="a"
}

AfterAll {
Clear-Item -Path env:testvar -ErrorAction SilentlyContinue
Clear-Item -Path env:testVar -ErrorAction SilentlyContinue
}

It "get-item testVar" {
(get-item env:\testVar).Value | Should -BeExactly "a"
}

It "get-item is case-sensitive/insensitive as appropriate" {
$expectedValue = "b"
if($IsWindows)
{
$expectedValue = "a"
}

(get-item env:\testvar).Value | Should -BeExactly $expectedValue
}
}
}