Skip to content

Commit

Permalink
Special case the posix locale in WildcardPattern (PowerShell#10186)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw authored and TravisEz13 committed Jul 26, 2019
1 parent 8f5b2c2 commit d2e81db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/System.Management.Automation/engine/regex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ StringComparison GetStringComparison()
{
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
}
}
}

0 comments on commit d2e81db

Please sign in to comment.