Skip to content

CompareInfo.IndexOf / LastIndexOf early-exit code paths do not account for zero-weight characters #34828

@GrabYourPitchforks

Description

@GrabYourPitchforks

Repro code:

Console.WriteLine(CultureInfo.InvariantCulture.CompareInfo.IndexOf(string.Empty, "\u200c"));

This should print 0 on all platforms unless we're running under the invariant globalization mode, in which case it should return -1. The reason for this is an incorrect early-exit in CompareInfo.IndexOf, as shown below.

if (source.Length == 0)
{
if (value.Length == 0)
{
return 0;
}
return -1;
}

This early exit does not account for the fact that empty strings and non-empty strings may compare as equal under certain collations if the non-empty strings consist only of zero-weight code points.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions