diff --git a/src/System.Management.Automation/engine/regex.cs b/src/System.Management.Automation/engine/regex.cs index 2c467bc62d..71c6c8bac8 100644 --- a/src/System.Management.Automation/engine/regex.cs +++ b/src/System.Management.Automation/engine/regex.cs @@ -146,7 +146,11 @@ namespace System.Management.Automation { stringComparison = Options.HasFlag(WildcardOptions.CultureInvariant) ? StringComparison.InvariantCultureIgnoreCase - : StringComparison.CurrentCultureIgnoreCase; + : CultureInfo.CurrentCulture.Name.Equals("en-US-POSIX", StringComparison.OrdinalIgnoreCase) + // The collation behavior of the POSIX locale (also known as the C locale) is case sensitive. + // For this specific locale, we use 'OrdinalIgnoreCase'. + ? StringComparison.OrdinalIgnoreCase + : StringComparison.CurrentCultureIgnoreCase; } else { diff --git a/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 b/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 index e42e06c2a4..4095477871 100644 --- a/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 +++ b/test/powershell/Language/Parser/LanguageAndParser.TestFollowup.Tests.ps1 @@ -304,8 +304,8 @@ Describe "Hash expression with if statement as value" -Tags "CI" { } } -Describe "Hashtable is case insensitive" -Tag CI { - It "When current culture is en-US-POSIX" -Skip:($IsWindows) { +Describe "Support case-insensitive comparison in Posix locale" -Tag CI { + It "Hashtable is case insensitive" -Skip:($IsWindows) { try { $oldCulture = [System.Globalization.CultureInfo]::CurrentCulture [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::new('en-US-POSIX') @@ -316,4 +316,20 @@ Describe "Hashtable is case insensitive" -Tag CI { [System.Globalization.CultureInfo]::CurrentCulture = $oldCulture } } + + It "Wildcard support case-insensitive matching" -Skip:($IsWindows) { + try { + $oldCulture = [System.Globalization.CultureInfo]::CurrentCulture + [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::new('en-US-POSIX') + + $wildcard1 = [WildcardPattern]::new("AbC*", [System.Management.Automation.WildcardOptions]::IgnoreCase) + $wildcard1.IsMatch("abcd") | Should -BeTrue + + $wildcard2 = [WildcardPattern]::new("DeF", [System.Management.Automation.WildcardOptions]::IgnoreCase); + $wildcard2.IsMatch("def") | Should -BeTrue + } + finally { + [System.Globalization.CultureInfo]::CurrentCulture = $oldCulture + } + } }