Skip to content

CompareInfo.IsSuffix sometimes incorrectly splits collation elements and returns 'true' #43897

@GrabYourPitchforks

Description

@GrabYourPitchforks

Repro (.NET 5 on ICU):

var ci = CultureInfo.InvariantCulture.CompareInfo;
int idx = ci.IndexOf("\u0600x", "x", CompareOptions.None);
bool isSuffix = ci.IsSuffix("\u0600x", "x", CompareOptions.None);
Console.WriteLine($"idx = {idx}, isSuffix = {isSuffix}");

This sample prints idx = -1, isSuffix = True. These return values are inconsistent with respect to each other. If IsSuffix returns true, then IndexOf must return a non-negative value. It's the contrapositive of the code comment at:

* If there exists in set S any entry with the tuple values (startPos = <anything>, endPos = searchString.Length),
* we say "'searchString' ends with 'value'", and the expression "searchString.EndsWith(value, comparer)"
* should evaluate to true. If there exists no such entry in set S, then we say "'searchString' does not
* start with 'value'", and the expression "searchString.EndsWith(value, comparer)" should evaluate to false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions