pull/9205/head
James Newton-King 3 years ago
parent 90afe0cfc6
commit c685d79368
No known key found for this signature in database
GPG Key ID: A66B2F456BF5526
  1. 4
      csharp/src/Google.Protobuf.Test/JsonParserTest.cs
  2. 4
      csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
  3. 11
      csharp/src/Google.Protobuf/JsonTokenizer.cs

@ -551,13 +551,9 @@ namespace Google.Protobuf
}
[Test]
// Skip these test cases in .NET 5 because floating point parsing supports bigger values.
// These big values won't throw an error in the test.
#if !NETCOREAPP3_1_OR_GREATER
[TestCase("1.7977e308")]
[TestCase("-1.7977e308")]
[TestCase("1e309")]
#endif
[TestCase("1,0")]
[TestCase("1.0.0")]
[TestCase("+1")]

@ -199,12 +199,8 @@ namespace Google.Protobuf
[TestCase("1e-")]
[TestCase("--")]
[TestCase("--1")]
// Skip these test cases in .NET 5 because floating point parsing supports bigger values.
// These big values won't throw an error in the test.
#if !NETCOREAPP3_1_OR_GREATER
[TestCase("-1.7977e308")]
[TestCase("1.7977e308")]
#endif
public void InvalidNumberValue(string json)
{
AssertThrowsAfter(json);

@ -471,9 +471,18 @@ namespace Google.Protobuf
// TODO: What exception should we throw if the value can't be represented as a double?
try
{
return double.Parse(builder.ToString(),
double result = double.Parse(builder.ToString(),
NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent,
CultureInfo.InvariantCulture);
// .NET Core 3.0 and later returns infinity if the number is too large or small to be represented.
// For compatibility with other Protobuf implementations the tokenizer should still throw.
if (double.IsInfinity(result))
{
throw reader.CreateException("Numeric value out of range: " + builder);
}
return result;
}
catch (OverflowException)
{

Loading…
Cancel
Save