Skip to content

Equality comparer returned by CollationInfo.GetCollationInfo("Latin1_General_CI_AS") doesn't work as expected #22

Description

Steps to reproduce:

  1. Create a database with collation Latin1_General_CI_AS
  2. Execute the following scripts in this database
create table unicode_test ([u_name1] nvarchar(10), [name1] varchar(10), [u_name2] nvarchar(10), [name2] varchar(10))
insert into unicode_test ([u_name1], [name1], [u_name2], [name2]) values (N'xxßmm', 'xxßmm', N'xxssmm', 'xxssmm');

select 'non_unicode_comparison' from [unicode_test] WHERE [name1] = [name2];
select 'unicode_comparison' from [unicode_test] WHERE [u_name1] = [u_name2]

Each select statement returns one row.
3) Create a sample application and add a reference to Microsoft.SqlServer.Management.SqlParser package (I tested v172.0.1). Then use this code to test the comparison:

var collation = CollationInfo.GetCollationInfo("Latin1_General_CI_AS");
var equalityComparer = collation.EqualityComparer;
            
var t1 = equalityComparer.Equals("ß", "SS");
var t2 = equalityComparer.Equals("ß", "ss");

Expected result: variables t1 and t2 are true.
Actual result: variables t1 and t2 are false.

The reason behind is that newer versions of .NET (>=5) switched to ICU-based comparison (where "ß" != "ss") and you didn't implement the workaround with CompareOptions.IgnoreNonSpace flag.

I totally understand that if this flag is used then the equality comparer will be exactly same as for Latin1_General_CI_AI collation, which is weird. But maybe someone can provide a detailed explanation why exactly you made a decision not to fix this bug and what is the recommended way of handling it?

Source issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions