mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
[Fix] If the local culture of the server was not english, numeric values greenfield were not properly interpreted
This commit is contained in:
@@ -22,13 +22,17 @@ namespace BTCPayServer.JsonConverters
|
|||||||
switch (token.Type)
|
switch (token.Type)
|
||||||
{
|
{
|
||||||
case JTokenType.Float:
|
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.Integer:
|
||||||
case JTokenType.String:
|
case JTokenType.String:
|
||||||
if (objectType == typeof(decimal) || objectType == typeof(decimal?) )
|
if (objectType == typeof(decimal) || objectType == typeof(decimal?) )
|
||||||
return decimal.Parse(token.ToString(), CultureInfo.InvariantCulture);
|
return decimal.Parse(token.ToString(), CultureInfo.InvariantCulture);
|
||||||
if (objectType == typeof(double) || objectType == typeof(double?))
|
if (objectType == typeof(double) || objectType == typeof(double?))
|
||||||
return double.Parse(token.ToString(), CultureInfo.InvariantCulture);
|
return double.Parse(token.ToString(), CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
throw new JsonSerializationException("Unexpected object type: " + objectType);
|
throw new JsonSerializationException("Unexpected object type: " + objectType);
|
||||||
case JTokenType.Null when objectType == typeof(decimal?) || objectType == typeof(double?):
|
case JTokenType.Null when objectType == typeof(decimal?) || objectType == typeof(double?):
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1979,10 +1979,13 @@ namespace BTCPayServer.Tests
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact(Timeout = TestTimeout)]
|
[Theory(Timeout = TestTimeout)]
|
||||||
|
[InlineData("DE-de")]
|
||||||
|
[InlineData("")]
|
||||||
[Trait("Fast", "Fast")]
|
[Trait("Fast", "Fast")]
|
||||||
public void NumericJsonConverterTests()
|
public void NumericJsonConverterTests(string culture)
|
||||||
{
|
{
|
||||||
|
System.Globalization.CultureInfo.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(culture);
|
||||||
JsonReader Get(string val)
|
JsonReader Get(string val)
|
||||||
{
|
{
|
||||||
return new JsonTextReader(new StringReader(val));
|
return new JsonTextReader(new StringReader(val));
|
||||||
|
|||||||
Reference in New Issue
Block a user