Fix issues that are variants of those #1182 (#1184)

* Catch excessive objects in json being parsed, even if following a comment.

* Include line info on excessive content for deserialisation.
This commit is contained in:
Jon Hanna
2017-01-19 10:33:30 +13:00
committed by James Newton-King
parent 76600dcc5b
commit 8956d3ca9c
9 changed files with 137 additions and 10 deletions
@@ -556,6 +556,31 @@ Parameter name: index");
Assert.AreEqual(3, (int)a[2]);
}
[Test]
public void Parse_ExcessiveContentJustComments()
{
string json = @"[1,2,3]/*comment*/
//Another comment.";
JArray a = JArray.Parse(json);
Assert.AreEqual(3, a.Count);
Assert.AreEqual(1, (int)a[0]);
Assert.AreEqual(2, (int)a[1]);
Assert.AreEqual(3, (int)a[2]);
}
[Test]
public void Parse_ExcessiveContent()
{
string json = @"[1,2,3]/*comment*/
//Another comment.
[]";
ExceptionAssert.Throws<JsonReaderException>(() => JArray.Parse(json),
"Additional text encountered after finished reading JSON content: [. Path '', line 3, position 0.");
}
[Test]
public void Parse_LineInfo()
{