Special case the posix locale in WildcardPattern (#10186)
This commit is contained in:
parent
8f5b2c241e
commit
d2e81dbc13
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user