Repository navigation
Add tests for non-culture-sensitive string methods - #1626
Merged
Merged
Conversation
The char and Rune overloads of string.Contains, StartsWith, EndsWith, IndexOf, and LastIndexOf are ordinal, so specifying a StringComparison is noise, as .NET 11 adds a StringComparison overload for each of them. CA1307 and CA1310 do not report them either. They can still be reported by setting MA0001.report_char_overloads to true. Fixes #1624 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JGXMy71bpLs2UyvA8LToaa
Revert the MA0001.report_char_overloads option: the char and Rune overloads of string.Contains, StartsWith, EndsWith, IndexOf, and LastIndexOf are ordinal, so MA0001 keeps reporting them when an overload with a StringComparison exists. string.Contains(string) is ordinal too, so it is now reported by MA0001 instead of MA0074. Add tests that check the reported rule and the code fix for all the string overloads that have a StringComparison overload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JGXMy71bpLs2UyvA8LToaa
Expose the documentation IDs of the methods whose default comparison is Ordinal or OrdinalIgnoreCase, and add a test for each of them that checks the method behaves as an ordinal comparison, using an input whose result differs with a culture-sensitive comparison. A method added to the list without a test makes the test fail. The Rune overloads of string are only available from .NET 11, so their tests are skipped until the tests run on .NET 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JGXMy71bpLs2UyvA8LToaa
…s reference The methods of Microsoft.Extensions.Primitives are excluded from the test that checks the default comparison of the non culture-sensitive methods. Also use escape sequences instead of invisible characters in the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JGXMy71bpLs2UyvA8LToaa
This was referenced Oct 8, 2026
Closed
Closed
Closed
Closed
Closed
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive test coverage for string methods that use ordinal or ordinal-ignore-case comparison by default, ensuring the analyzer correctly identifies when explicit
StringComparisonparameters are needed.Key Changes
StringMethods_ReportDiagnosticDependingOnTheDefaultComparisoncovering 38 different string method overloads with various parameter combinations (char, string, Rune arguments)NonCultureSensitiveMethod_DefaultComparisonIsOrdinalthat validates the actual runtime behavior of non-culture-sensitive methods using soft hyphen (\u00AD) as a test character to demonstrate the difference between ordinal and culture-sensitive comparisonsNonCultureSensitiveMethodDocumentationIdsproperty inUseStringComparisonAnalyzerto enable test reuse and maintainabilitySystem.Security.Claims,System.Security.Principal, andSystem.TextnamespacesEmptyIdentityandCopiedClaimsIdentitytest helper classes to supportClaimsIdentitytestingNotable Implementation Details
\u00AD) which is ignored in linguistic comparisons but not in ordinal comparisons, making it ideal for demonstrating the behavioral differences.Contains()) and static methods (e.g.,string.Equals())StringComparisonparametershttps://claude.ai/code/session_01JGXMy71bpLs2UyvA8LToaa