8000 Fix error in windows provider when the environment as an existing set of variables name that only differs by case by TravisEz13 · Pull Request #6320 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fix error in windows provider when the environment as an existing set of variables name that only differs by case #6320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2018
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
}
}
}
0