-Fixed JToken Load and Parse methods not checking for incomplete content
This commit is contained in:
@@ -429,5 +429,12 @@ Parameter name: index")]
|
||||
Assert.AreEqual(1, a.Count);
|
||||
Assert.AreEqual(1, (int)a[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(Exception), ExpectedMessage = "Unexpected end of content while loading JArray.")]
|
||||
public void ParseIncomplete()
|
||||
{
|
||||
JArray.Parse("[1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -464,13 +464,17 @@ Parameter name: arrayIndex")]
|
||||
public void DeserializeClassManually()
|
||||
{
|
||||
string jsonText = @"{
|
||||
""short"":{
|
||||
""original"":""http://www.foo.com/"",
|
||||
""short"":""krehqk"",
|
||||
""error"":{
|
||||
""code"":0,
|
||||
""msg"":""No action taken""}
|
||||
}";
|
||||
""short"":
|
||||
{
|
||||
""original"":""http://www.foo.com/"",
|
||||
""short"":""krehqk"",
|
||||
""error"":
|
||||
{
|
||||
""code"":0,
|
||||
""msg"":""No action taken""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
JObject json = JObject.Parse(jsonText);
|
||||
|
||||
@@ -1490,6 +1494,63 @@ Parameter name: arrayIndex")]
|
||||
JObject.Parse(json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(Exception), ExpectedMessage = "Unexpected end of content while loading JObject.")]
|
||||
public void ParseIncomplete()
|
||||
{
|
||||
JObject.Parse("{ foo:");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoadFromNestedObject()
|
||||
{
|
||||
string jsonText = @"{
|
||||
""short"":
|
||||
{
|
||||
""error"":
|
||||
{
|
||||
""code"":0,
|
||||
""msg"":""No action taken""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
JsonReader reader = new JsonTextReader(new StringReader(jsonText));
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
|
||||
JObject o = (JObject)JToken.ReadFrom(reader);
|
||||
Assert.IsNotNull(o);
|
||||
Assert.AreEqual(@"{
|
||||
""code"": 0,
|
||||
""msg"": ""No action taken""
|
||||
}", o.ToString(Formatting.Indented));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(Exception), ExpectedMessage = "Unexpected end of content while loading JObject.")]
|
||||
public void LoadFromNestedObjectIncomplete()
|
||||
{
|
||||
string jsonText = @"{
|
||||
""short"":
|
||||
{
|
||||
""error"":
|
||||
{
|
||||
""code"":0";
|
||||
|
||||
JsonReader reader = new JsonTextReader(new StringReader(jsonText));
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
|
||||
JToken.ReadFrom(reader);
|
||||
}
|
||||
|
||||
#if !SILVERLIGHT
|
||||
[Test]
|
||||
public void GetProperties()
|
||||
|
||||
Reference in New Issue
Block a user