-Fixed parsing large floating point numbers
This commit is contained in:
@@ -1260,6 +1260,9 @@ bye", reader.Value);
|
||||
reader = new JsonTextReader(new StringReader(long.MaxValue.ToString()));
|
||||
ExceptionAssert.Throws<OverflowException>("Arithmetic operation resulted in an overflow.", () => reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("9999999999999999999999999999999999999999999999999999999999999999999999999999asdasdasd"));
|
||||
ExceptionAssert.Throws<FormatException>("Input string was not in a correct format.", () => reader.ReadAsInt32());
|
||||
|
||||
reader = new JsonTextReader(new StringReader("1E-06"));
|
||||
ExceptionAssert.Throws<FormatException>("Input string was not in a correct format.", () => reader.ReadAsInt32());
|
||||
|
||||
|
||||
@@ -446,6 +446,16 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void DeserializeLargeFloat()
|
||||
{
|
||||
object o = JsonConvert.DeserializeObject("100000000000000000000000000000000000000.0");
|
||||
|
||||
CustomAssert.IsInstanceOfType(typeof(double), o);
|
||||
|
||||
Assert.IsTrue(MathUtils.ApproxEquals(1E+38, (double)o));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeDeserializeRegex()
|
||||
{
|
||||
|
||||
@@ -1194,8 +1194,10 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
|
||||
int initialDepth = reader.Depth;
|
||||
|
||||
JsonContract collectionItemContract = GetContractSafe(contract.CollectionItemType);
|
||||
JsonConverter collectionItemConverter = GetConverter(collectionItemContract, null, contract, containerProperty);
|
||||
if (contract.ItemContract == null)
|
||||
contract.ItemContract = GetContractSafe(contract.CollectionItemType);
|
||||
|
||||
JsonConverter collectionItemConverter = GetConverter(contract.ItemContract, null, contract, containerProperty);
|
||||
|
||||
int? previousErrorIndex = null;
|
||||
|
||||
@@ -1204,7 +1206,7 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ReadForType(reader, collectionItemContract, collectionItemConverter != null))
|
||||
if (ReadForType(reader, contract.ItemContract, collectionItemConverter != null))
|
||||
{
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
@@ -1219,7 +1221,7 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
||||
if (collectionItemConverter != null && collectionItemConverter.CanRead)
|
||||
value = DeserializeConvertable(collectionItemConverter, reader, contract.CollectionItemType, null);
|
||||
else
|
||||
value = CreateValueInternal(reader, contract.CollectionItemType, collectionItemContract, null, contract, containerProperty, null);
|
||||
value = CreateValueInternal(reader, contract.CollectionItemType, contract.ItemContract, null, contract, containerProperty, null);
|
||||
|
||||
list.Add(value);
|
||||
break;
|
||||
|
||||
@@ -611,7 +611,21 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
// overflow has caused the number to loop around
|
||||
if (newValue > result)
|
||||
{
|
||||
i++;
|
||||
|
||||
// double check the rest of the string that there wasn't anything invalid
|
||||
// invalid result takes precedence over overflow result
|
||||
for (; i < end; i++)
|
||||
{
|
||||
c = chars[i] - '0';
|
||||
|
||||
if (c < 0 || c > 9)
|
||||
throw new FormatException("Input string was not in a correct format.");
|
||||
}
|
||||
|
||||
throw new OverflowException();
|
||||
}
|
||||
|
||||
result = newValue;
|
||||
}
|
||||
@@ -662,7 +676,22 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
// overflow has caused the number to loop around
|
||||
if (newValue > value)
|
||||
{
|
||||
i++;
|
||||
|
||||
// double check the rest of the string that there wasn't anything invalid
|
||||
// invalid result takes precedence over overflow result
|
||||
for (; i < end; i++)
|
||||
{
|
||||
c = chars[i] - '0';
|
||||
|
||||
if (c < 0 || c > 9)
|
||||
return ParseResult.Invalid;
|
||||
}
|
||||
|
||||
return ParseResult.Overflow;
|
||||
|
||||
}
|
||||
|
||||
value = newValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user