-Test
This commit is contained in:
@@ -26,6 +26,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
using System.Numerics;
|
||||
#endif
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
#if !(NET20 || NET35)
|
||||
@@ -995,17 +998,22 @@ now brown cow?", '"', true);
|
||||
Assert.AreEqual("Bad Boys", m.Name);
|
||||
}
|
||||
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
[Test]
|
||||
public void IntegerLengthOverflows()
|
||||
{
|
||||
// Maximum javascript number length (in characters) is 380
|
||||
|
||||
dynamic d = JObject.Parse(@"{""biginteger"":" + new String('9', 380) + "}");
|
||||
JObject o = JObject.Parse(@"{""biginteger"":" + new String('9', 380) + "}");
|
||||
JValue v = (JValue)o["biginteger"];
|
||||
Assert.AreEqual(JTokenType.Integer, v.Type);
|
||||
Assert.AreEqual(typeof(BigInteger), v.Value.GetType());
|
||||
Assert.AreEqual(BigInteger.Parse(new String('9', 380)), (BigInteger)v.Value);
|
||||
|
||||
ExceptionAssert.Throws<JsonReaderException>(
|
||||
"JSON integer " + new String('9', 381) + " is too large to parse. Path 'biginteger', line 1, position 395.",
|
||||
() => JObject.Parse(@"{""biginteger"":" + new String('9', 381) + "}"));
|
||||
}
|
||||
#endif
|
||||
|
||||
//[Test]
|
||||
public void StackOverflowTest()
|
||||
|
||||
@@ -56,8 +56,7 @@ namespace Newtonsoft.Json
|
||||
public class JsonTextReader : JsonReader, IJsonLineInfo
|
||||
{
|
||||
private const char UnicodeReplacementChar = '\uFFFD';
|
||||
|
||||
private const int MaximumJavascriptIntegerLengthInCharacters = 380;
|
||||
private const int MaximumJavascriptIntegerCharacterLength = 380;
|
||||
|
||||
private readonly TextReader _reader;
|
||||
private char[] _chars;
|
||||
@@ -1270,10 +1269,10 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
#if !(NET20 || NET35 || PORTABLE40 || PORTABLE)
|
||||
string number = _stringReference.ToString();
|
||||
if (number.Length > MaximumJavascriptIntegerLengthInCharacters)
|
||||
|
||||
if (number.Length > MaximumJavascriptIntegerCharacterLength)
|
||||
throw JsonReaderException.Create(this, "JSON integer {0} is too large to parse.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString()));
|
||||
|
||||
|
||||
numberValue = BigInteger.Parse(number, CultureInfo.InvariantCulture);
|
||||
numberType = JsonToken.Integer;
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user