Skip to content

IdnMapping.GetAscii throws for some inputs in GlobalizationMode.Invariant #37349

Open
@stephentoub

Description

@stephentoub
using System;
using System.Globalization;

class Program
{
    static void Main()
    {
        //Environment.SetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_USENLS", "1");
        //Environment.SetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1");
        Console.WriteLine(new IdnMapping().GetAscii("\xD83D\xDE00"));
    }
}

This works fine with both NLS and ICU. But when GlobalizationMode.Invariant is enabled (uncomment the relevant line above), it throws an exception:

Unhandled exception. System.ArgumentException: Left to right characters may not be mixed with right to left characters in IDN labels. (Parameter 'unicode')
   at System.Globalization.IdnMapping.PunycodeEncode(String unicode)
   at System.Globalization.IdnMapping.GetAsciiInvariant(String unicode, Int32 index, Int32 count)
   at System.Globalization.IdnMapping.GetAscii(String unicode, Int32 index, Int32 count)
   at System.Globalization.IdnMapping.GetAscii(String unicode, Int32 index)
   at System.Globalization.IdnMapping.GetAscii(String unicode)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions