dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.94k stars 4.64k forks source link

Discrepancy between Ubuntu and Windows when converting negative numbers to string #25626

Closed ppekrol closed 4 years ago

ppekrol commented 6 years ago

Windows:

Product Information:
 Version:            2.1.103
 Commit SHA-1 hash:  60218cecb5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16299
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.103\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.6
  Build    : 74b1c703813c8910df5b96f304b0f2b78cdf194d

Ubuntu:

Product Information:
 Version:            2.1.102
 Commit SHA-1 hash:  8d409357db

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  16.04
 OS Platform: Linux
 RID:         ubuntu.16.04-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.102/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.6
  Build    : 74b1c703813c8910df5b96f304b0f2b78cdf194d

Test:

        [Fact]
        public void ShouldPass()
        {
            long number = -1L;

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("en-US");
            var s1 = number.ToString();

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("sv-SE");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("sv-SE");
            var s2 = number.ToString();

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            Assert.Equal(s1, s2);
        }

On Windows everything is fine, but on Ubuntu I'm getting:

Assert.Equal() Failure
          ↓ (pos 0)
Expected: -1
Actual:   −1
          ↑ (pos 0)
   at SlowTests.Tests.Spatial.SpatialTest.T1() in /home/ppekrol/Workspaces/ravendb/test/SlowTests/Tests/Spatial/Spatial.cs:line 279

Also when '−1' is used as a header to 'Kestrel' the response status code is set to 400, but this might be expected, because this is a special character?

ppekrol commented 6 years ago

Found https://github.com/dotnet/coreclr/issues/1734 Closing...