Skip to content

Commit 8294efb

Browse files
nenadvicenticrusscam
authored andcommitted
Fallback parsing for doubles should use InvariantCulture (#4059)
Closes #4057
1 parent ee84e1a commit 8294efb

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Elasticsearch.Net/Utf8Json/Internal/DoubleConversion/StringToDoubleConverter.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#endregion
2424

2525
using System;
26+
using System.Globalization;
2627
using System.Text;
2728

2829
namespace Elasticsearch.Net.Utf8Json.Internal.DoubleConversion
@@ -636,7 +637,7 @@ static double StringToIeee(
636637
input++;
637638
}
638639
var laststr = Encoding.UTF8.GetString(fallbackbuffer, 0, fallbackI);
639-
return double.Parse(laststr);
640+
return double.Parse(laststr, CultureInfo.InvariantCulture);
640641
}
641642

642643
processed_characters_count = (current - input);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using Elastic.Xunit.XunitPlumbing;
3+
using FluentAssertions;
4+
using Nest;
5+
using Tests.Core.Extensions;
6+
using Tests.Core.Serialization;
7+
8+
namespace Tests.Reproduce
9+
{
10+
public class GithubIssue4057
11+
{
12+
[U]
13+
[UseCulture("sv-SE")]
14+
public void DoubleAffectedByPrecisionProblemDeserializesCorrectlyIndependentOfCurrentCulture()
15+
{
16+
var expected = 16.27749494276941D;
17+
18+
var tester = SerializationTester.Default;
19+
var actual = tester.Deserializes<double>("16.27749494276941");
20+
21+
actual.Result.Should().NotBe(expected); // we are expecting precision problem;
22+
Math.Round(actual.Result, 13).Should().Be(Math.Round(expected, 13));
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)