mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 22:25:28 +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:
parent
fd27bd94e2
commit
e50c9266b4
2 changed files with 10 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Reference in a new issue