Skip to content

Equals and GetHashCode mismatch with StringComparer.InvariantCulture #1062

@VladimirReshetnikov

Description

@VladimirReshetnikov

Compile and run:

using System;

static class Program
{
    static void Main()
    {
        // U+FFFD is REPLACEMENT CHARACTER
        Console.WriteLine(StringComparer.InvariantCulture.Equals("", "\uFFFD"));
        Console.WriteLine(StringComparer.InvariantCulture.GetHashCode("") ==
                          StringComparer.InvariantCulture.GetHashCode("\uFFFD"));
    }
}

ACTUAL:

True
False

EXPECTED:
The second Boolean value is True if the first one is True.


OS ver is Microsoft Windows [Version 10.0.17763.914]

%SystemRoot%\System32\kernel32.dll
File version: 10.0.17763.475
File SHA1: 8de080d3295fb21475715d4051ec9dbc3df972ba


The issue occurs both on:

%ProgramFiles%\dotnet\shared\Microsoft.NETCore.App\3.1.0\.version
65f04fb6db7a5e198d05dbebd5c4ad21eb018f89
3.1.0

and

%ProgramFiles%\dotnet\shared\Microsoft.NETCore.App\5.0.0-alpha.1.19564.1\.version
c77948d92a2f950140f09384f057cb893ec3955a
5.0.0-alpha.1.19564.1

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions