Skip to content

Problems with Formatting of numbers and dates if you run on non English CultureInfo #4

@andi0b

Description

@andi0b

Describe the bug

Formatting values via this library ignores the CultureInfo set to Handlebars.Configuration.FormatProvider.

Numbers and dates will always be formatted with the culture of the current thread. Furthermore there are some tests failing if you run it on a non English locale.

It seems PR #2 broke it.

Expected behavior:

Format JToken with Handlebars.Configuration.FormatProvider

If I set Handlebars.Configuration.FormatProvider to CultureInfo.Invariant I expect numbers to be formatted like 3.14 instead of like my locale would format: 3,14

Test to reproduce

Run current tests on a non English locale (in my case German/Austria) and some will fail:

[xUnit.net 00:00:01.07]     HandlebarsDotNet.Extension.Test.JsonTests.ValueTypes(value: "22474.1") [FAIL]
  Fehler HandlebarsDotNet.Extension.Test.JsonTests.ValueTypes(value: "22474.1") [11 ms]
  Fehlermeldung:
   Assert.Equal() Failure
               ↓ (pos 5)
Expected: 22474.1
Actual:   22474,1
               ↑ (pos 5)
  Stapelverfolgung:
     at HandlebarsDotNet.Extension.Test.JsonTests.ValueTypes(String value) in C:\Users\Andreas\git\github\Handlebars.Net.Extension.NewtonsoftJson\source\Handlebars.Extension.Test\JsonTests.cs:line 50
[xUnit.net 00:00:01.26]     HandlebarsDotNet.Extension.Test.JsonTests.ArrayAccessByIndex(handlebars: HandlebarsEnvironment { Configuration = HandlebarsConfiguration { AliasProviders = [...], BlockHelpers = [...], Compatibility = Compatibility { ... }, CompileTimeConfiguration = CompileTimeConfiguration { ... }, ExpressionNameResolver = null, ... } }) [FAIL]
  Fehler HandlebarsDotNet.Extension.Test.JsonTests.ArrayAccessByIndex(handlebars: HandlebarsEnvironment { Configuration = HandlebarsConfiguration { AliasProviders = [...], BlockHelpers = [...], Compatibility = Compatibility { ... }, CompileTimeConfiguration = CompileTimeConfiguration { ... }, ExpressionNameResolver = null, ... } }) [6 ms]
  Fehlermeldung:
   Assert.Equal() Failure
                        ↓ (pos 14)
Expected: 1,True,False,1.1,,
Actual:   1,True,False,1,1,,
                        ↑ (pos 14)
  Stapelverfolgung:
     at HandlebarsDotNet.Extension.Test.JsonTests.ArrayAccessByIndex(IHandlebars handlebars) in C:\Users\Andreas\git\github\Handlebars.Net.Extension.NewtonsoftJson\source\Handlebars.Extension.Test\JsonTests.cs:line 222

Fehler!      : Fehler:     2, erfolgreich:    25, übersprungen:     0, gesamt:    27, Dauer: 257 ms - Handlebars.Extension.Test.dll (netcoreapp2.1)

I am going to look into this problem and will try to provide a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions