From 9793ed2c6830e5cb1d4d797901a529234f30ac51 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 9 Jan 2019 20:11:43 -0800 Subject: [PATCH] Change hashtable to use OrdinalIgnoreCase to be case-insensitive in all Cultures (#8566) Ubuntu18.04 seems to default to C.UTF-8 for LANG (representing InvariantCulture) which results in a case-sensitive hashtable since CurrentCultureIgnoreCase doesn't work for that culture. Fix is to use OrdinalIgnoreCase instead. --- src/System.Management.Automation/engine/parser/Compiler.cs | 4 ++-- .../Parser/LanguageAndParser.TestFollowup.Tests.ps1 | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/parser/Compiler.cs b/src/System.Management.Automation/engine/parser/Compiler.cs index aa7873145..2b641bf9b 100644 --- a/src/System.Management.Automation/engine/parser/Compiler.cs +++ b/src/System.Management.Automation/engine/parser/Compiler.cs @@ -538,7 +538,7 @@ namespace System.Management.Automation.Language internal static readonly Expression CompareOptionsNone = Expression.Constant(CompareOptions.None); internal static readonly Expression Ordinal = Expression.Constant(StringComparison.Ordinal); internal static readonly Expression InvariantCulture = Expression.Constant(CultureInfo.InvariantCulture); - internal static readonly Expression CurrentCultureIgnoreCaseComparer = Expression.Constant(StringComparer.CurrentCultureIgnoreCase, typeof(StringComparer)); + internal static readonly Expression OrdinalIgnoreCaseComparer = Expression.Constant(StringComparer.OrdinalIgnoreCase, typeof(StringComparer)); internal static readonly Expression CatchAllType = Expression.Constant(typeof(ExceptionHandlingOps.CatchAll), typeof(Type)); internal static readonly Expression Empty = Expression.Empty(); internal static Expression GetExecutionContextFromTLS = @@ -5756,7 +5756,7 @@ namespace System.Management.Automation.Language yield return Expression.Assign(temp, Expression.New(ordered ? CachedReflectionInfo.OrderedDictionary_ctor : CachedReflectionInfo.Hashtable_ctor, ExpressionCache.Constant(keyValuePairs.Count), - ExpressionCache.CurrentCultureIgnoreCaseComparer.Cast(typeof(IEqualityComparer)))); + ExpressionCache.OrdinalIgnoreCaseComparer.Cast(typeof(IEqualityComparer)))); for (int index = 0; index < keyValuePairs.Count; index++) { var keyValuePair = keyValuePairs[index]; diff --git a/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 b/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 index da50b2e55..edc6a297b 100644 --- a/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 +++ b/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 @@ -303,3 +303,9 @@ Describe "Hash expression with if statement as value" -Tags "CI" { $hash['h'] | Should -BeExactly 'h' } } + +Describe "Hashtable is case insensitive" -Tag CI { + It "When LANG is C.UTF-8" -Skip:($IsWindows) { + sh -c 'LANG=C.UTF-8 pwsh -NoProfile -Command ''$h=@{p=1};$h.P''' | Should -Be 1 + } +}