[Fix] If the local culture of the server was not english, numeric values greenfield were not properly interpreted

This commit is contained in:
nicolas.dorier 2021-10-26 00:46:09 +09:00
parent fd27bd94e2
commit e50c9266b4
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
2 changed files with 10 additions and 3 deletions

View file

@ -22,13 +22,17 @@ namespace BTCPayServer.JsonConverters
switch (token.Type)
{
case JTokenType.Float:
if (objectType == typeof(decimal) || objectType == typeof(decimal?))
return token.Value<decimal>();
if (objectType == typeof(double) || objectType == typeof(double?))
return token.Value<double>();
throw new JsonSerializationException("Unexpected object type: " + objectType);
case JTokenType.Integer:
case JTokenType.String:
if (objectType == typeof(decimal) || objectType == typeof(decimal?) )
return decimal.Parse(token.ToString(), CultureInfo.InvariantCulture);
if (objectType == typeof(double) || objectType == typeof(double?))
return double.Parse(token.ToString(), CultureInfo.InvariantCulture);
throw new JsonSerializationException("Unexpected object type: " + objectType);
case JTokenType.Null when objectType == typeof(decimal?) || objectType == typeof(double?):
return null;

View file

@ -1979,10 +1979,13 @@ namespace BTCPayServer.Tests
}
[Fact(Timeout = TestTimeout)]
[Theory(Timeout = TestTimeout)]
[InlineData("DE-de")]
[InlineData("")]
[Trait("Fast", "Fast")]
public void NumericJsonConverterTests()
public void NumericJsonConverterTests(string culture)
{
System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(culture);
JsonReader Get(string val)
{
return new JsonTextReader(new StringReader(val));