Skip to content

StringComparison.OrdinalIgnoreCase does not consistently match ToUpperInvariant #67873

Open

Description

@GrabYourPitchforks

Per the following two documents, comparing strings using StringComparison.OrdinalIgnoreCase is explicitly documented as equivalent to calling ToUpperInvariant on each string, then performing an ordinal comparison against the contents.

These statements within the docs imply that ToUpperInvariant and ToLowerInvariant are ordinal case conversions ("simple case mapping"), not linguistic case conversions. However, it looks like we're not consistenly following this pattern.

string s1 = "s";
string s2 = "\u017f"; // Latin Sharp S, which uppercase-maps to a normal ASCII "S"
Console.WriteLine(s1.Equals(s2, StringComparison.OrdinalIgnoreCase)); // False
Console.WriteLine(s1.ToUpperInvariant() == s2.ToUpperInvariant()); // True

This has collateral impact. For example, recent PRs like #67758 assume that non-ASCII characters cannot case-map to ASCII characters, which is not a guarantee offered by Unicode, but which might be a guarantee we'd be willing to make separately within the runtime by munging the Unicode tables.

See also #30960 for further discussion on case mapping as a more general Unicode concept.

/cc @tarekgh, who had thoughts on this offline.

Activity

  1. ghost added
    untriaged
    on Apr 11, 2022
  2. removed
    untriaged
    on Apr 11, 2022
  3. added this to the Future milestone on Apr 11, 2022
  4. modified the milestones: Future, 9.0.0 on Nov 21, 2023
  5. ericstj commented on Aug 6, 2024

    @ericstj
    Member

    @tarekgh is there anything planned for this issue in .NET 9.0?

  6. modified the milestones: 9.0.0, 10.0.0 on Aug 6, 2024
  7. modified the milestones: 10.0.0, Future on Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions