-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()));
|
reader = new JsonTextReader(new StringReader(long.MaxValue.ToString()));
|
||||||
ExceptionAssert.Throws<OverflowException>("Arithmetic operation resulted in an overflow.", () => reader.ReadAsInt32());
|
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"));
|
reader = new JsonTextReader(new StringReader("1E-06"));
|
||||||
ExceptionAssert.Throws<FormatException>("Input string was not in a correct format.", () => reader.ReadAsInt32());
|
ExceptionAssert.Throws<FormatException>("Input string was not in a correct format.", () => reader.ReadAsInt32());
|
||||||
|
|
||||||
|
|||||||
@@ -446,6 +446,16 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}
|
}
|
||||||
#endif
|
#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]
|
[Test]
|
||||||
public void SerializeDeserializeRegex()
|
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;
|
int initialDepth = reader.Depth;
|
||||||
|
|
||||||
JsonContract collectionItemContract = GetContractSafe(contract.CollectionItemType);
|
if (contract.ItemContract == null)
|
||||||
JsonConverter collectionItemConverter = GetConverter(collectionItemContract, null, contract, containerProperty);
|
contract.ItemContract = GetContractSafe(contract.CollectionItemType);
|
||||||
|
|
||||||
|
JsonConverter collectionItemConverter = GetConverter(contract.ItemContract, null, contract, containerProperty);
|
||||||
|
|
||||||
int? previousErrorIndex = null;
|
int? previousErrorIndex = null;
|
||||||
|
|
||||||
@@ -1204,7 +1206,7 @@ To fix this error either change the JSON to a {1} or change the deserialized typ
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (ReadForType(reader, collectionItemContract, collectionItemConverter != null))
|
if (ReadForType(reader, contract.ItemContract, collectionItemConverter != null))
|
||||||
{
|
{
|
||||||
switch (reader.TokenType)
|
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)
|
if (collectionItemConverter != null && collectionItemConverter.CanRead)
|
||||||
value = DeserializeConvertable(collectionItemConverter, reader, contract.CollectionItemType, null);
|
value = DeserializeConvertable(collectionItemConverter, reader, contract.CollectionItemType, null);
|
||||||
else
|
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);
|
list.Add(value);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -611,7 +611,21 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
// overflow has caused the number to loop around
|
// overflow has caused the number to loop around
|
||||||
if (newValue > result)
|
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();
|
throw new OverflowException();
|
||||||
|
}
|
||||||
|
|
||||||
result = newValue;
|
result = newValue;
|
||||||
}
|
}
|
||||||
@@ -662,8 +676,23 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
|
|
||||||
// overflow has caused the number to loop around
|
// overflow has caused the number to loop around
|
||||||
if (newValue > value)
|
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;
|
return ParseResult.Overflow;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
value = newValue;
|
value = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user