You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason for this are the following methods in class SmartSettings:
internalIEqualityComparer<string>GetCaseSensitivityComparer(){{switch(CaseSensitivity){case CaseSensitivityType.CaseSensitive:return StringComparer.CurrentCulture;case CaseSensitivityType.CaseInsensitive:return StringComparer.CurrentCultureIgnoreCase;default:thrownew InvalidOperationException($"The case sensitivity type [{CaseSensitivity}] is unknown.");}}}internal StringComparison GetCaseSensitivityComparison(){{switch(CaseSensitivity){case CaseSensitivityType.CaseSensitive:return StringComparison.CurrentCulture;case CaseSensitivityType.CaseInsensitive:return StringComparison.CurrentCultureIgnoreCase;default:thrownew InvalidOperationException($"The case sensitivity type [{CaseSensitivity}] is unknown.");}}}
The string are compared linguistically since many years. However, different platforms are handling this in different ways, and .NetCore makes use of the functions provided by the OS.
In most cases it can be assumed that selectors and variables should be comparable without language specifics. Examples why:
// Turkish character variations for "I"
CultureInfo.CurrentCulture =new CultureInfo("en-US");string.Equals("i","I", StringComparison.CurrentCultureIgnoreCase);// truestring.Equals("i","İ", StringComparison.CurrentCultureIgnoreCase);// false
CultureInfo.CurrentCulture =new CultureInfo("tr-TR");string.Equals("i","I", StringComparison.CurrentCultureIgnoreCase));// falsestring.Equals("i","İ", StringComparison.CurrentCultureIgnoreCase));// true// The Thai culture doesn't contain '.', so comparisons can be a surprising (tested on Ubuntu v18):
CultureInfo.CurrentCulture =new CultureInfo("th_TH.UTF8");"Test".StartsWith(".", StringComparison.CurrentCulture);// true!!!"12.4".IndexOf(".", StringComparison.CurrentCulture);// 0
Conclusion: Internal comparisons should not be culture-specific, but Ordinal or OrdinalIgnoreCase respectively. However, this must be considered as a breaking change.
axunonb
changed the title
Unit test fail on Linux for case-insensitive string comparisons
Unit tests fail on Linux for case-insensitive string comparisons
Oct 22, 2019
While unit test succeed on Windows .NetFramework and Windows .NetCore, they fail on Linux .NetCore.
The text was updated successfully, but these errors were encountered: