amazon-ion / ion-dotnet

A .NET implementation of Amazon Ion.
https://amazon-ion.github.io/ion-docs/
Other
56 stars 31 forks source link

`IonTextWriterBuilder` produces invalid JSON with different cultures #139

Closed KirkEasterson closed 2 years ago

KirkEasterson commented 2 years ago

Issue #, if available: #137

Description of changes: To summarize the core issue, some cultures parse negative integers differently. For example, "en-US" will return -1 (dash) when (-1).ToString(); is called. But "sv-SE" will return −1 (minus sign). This can be observed in BigDecimal.cs on line 455: sb.Append(-d);. This reults in invalid JSON being generated when using an IonTextWriterBuilder to down-convert ION to JSON. The problematic line was changed to sb.Append((-d).ToString(CultureInfo.InvariantCulture));. Tests were added to TextWriterJsonTest.cs and BigDecimalTest.cs to ensure the correct behavior.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.