Make Get-Item env: case-aware on Unix

Fix #1196
This commit is contained in:
Sergei Vorobev 2016-07-28 14:19:36 -07:00
parent 9b7ff0a384
commit a704a53f08
2 changed files with 59 additions and 29 deletions

View file

@ -190,8 +190,15 @@ namespace Microsoft.PowerShell.Commands
///
internal override IDictionary GetSessionStateTable ()
{
// Environment variables are case-sensitive on Unix and
// case-insensitive on Windows
#if UNIX
Dictionary<string, DictionaryEntry> providerTable =
new Dictionary<string, DictionaryEntry>(StringComparer.Ordinal);
#else
Dictionary<string, DictionaryEntry> providerTable =
new Dictionary<string, DictionaryEntry>(StringComparer.OrdinalIgnoreCase);
#endif
// The environment variables returns a dictionary of keys and values that are
// both strings. We want to return a dictionary with the key as a string and

View file

@ -1,4 +1,7 @@
Describe "Get-ChildItem" -Tags "CI" {
Context 'FileSystem provider' {
It "Should list the contents of the current folder" {
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
}
@ -34,3 +37,23 @@ Describe "Get-ChildItem" -Tags "CI" {
$files[4].Name | Should Be "D"
}
}
Context 'Env: Provider' {
It 'can handle mixed case in Env variables' {
try
{
$env:__FOOBAR = 'foo'
$env:__foobar = 'bar'
$foobar = Get-Childitem env: | ? {$_.Name -eq '__foobar'}
$count = if ($IsWindows) { 1 } else { 2 }
($foobar | measure).Count | Should Be $count
}
catch
{
Get-ChildItem env: | ? {$_.Name -eq '__foobar'} | Remove-Item -ErrorAction SilentlyContinue
}
}
}
}