Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ban InvariantCulture/InvariantCultureIgnoreCase #18

Merged
merged 1 commit into from
May 8, 2024
Merged

Conversation

meziantou
Copy link
Contributor

Description of changes

These symbols are almost never ok, so we should ban them and suggest using Ordinal or OrdinalIgnoreCase. Using InvariantCulture to compare 2 strings is not invariant as it uses a linguistical rules instead of comparing bytes. So, it can lead to unexpected results. Also, it’s much slower.

// true, but I don't know this is what developers expect
string.Equals("a\0bc", "abc", StringComparison.InvariantCulture)
string.Equals("A꙰B", "AB", StringComparison.InvariantCultureIgnoreCase)

// true using NLS, false using ICU
string.Equals("ss", "ß", StringComparison.InvariantCultureIgnoreCase)

Breaking changes

It may break build on projects using any of these symbols.

  • Replace InvariantCulture with Ordinal
  • Replace InvariantCultureIgnoreCase with OrdinalIgnoreCase
  • Use #pragma warning disable or SuppressMessageAttribute

Additional checks

  • Updated the documentation of the project to reflect the changes
  • Added new tests that cover the code changes

@meziantou meziantou marked this pull request as ready for review May 8, 2024 15:55
@meziantou meziantou requested a review from a team as a code owner May 8, 2024 15:55
@meziantou meziantou merged commit 088f628 into main May 8, 2024
3 checks passed
@meziantou meziantou deleted the feature/IDP-1284 branch May 8, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants