diff options
author | JamesNK <james@newtonking.com> | 2010-12-27 13:06:35 +0300 |
---|---|---|
committer | JamesNK <james@newtonking.com> | 2010-12-27 13:06:35 +0300 |
commit | f32e1f53c58a8023fb647531ccafdbacc11cf4e4 (patch) | |
tree | a66aa48e081dd7bdee8bdbdbfe105c4e2a95ccf8 /Src/Newtonsoft.Json | |
parent | 1297d64457363c37cc2794cf2031492400179336 (diff) |
-Fixed JToken Load and Parse methods not checking for incomplete content
Diffstat (limited to 'Src/Newtonsoft.Json')
-rw-r--r-- | Src/Newtonsoft.Json/Linq/JArray.cs | 5 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Linq/JConstructor.cs | 5 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Linq/JContainer.cs | 15 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Linq/JObject.cs | 6 | ||||
-rw-r--r-- | Src/Newtonsoft.Json/Linq/JProperty.cs | 5 |
5 files changed, 20 insertions, 16 deletions
diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs index 82708cc..6b4dc5f 100644 --- a/Src/Newtonsoft.Json/Linq/JArray.cs +++ b/Src/Newtonsoft.Json/Linq/JArray.cs @@ -111,10 +111,7 @@ namespace Newtonsoft.Json.Linq JArray a = new JArray();
a.SetLineInfo(reader as IJsonLineInfo);
- if (!reader.Read())
- throw new Exception("Error reading JArray from JsonReader.");
-
- a.ReadContentFrom(reader);
+ a.ReadTokenFrom(reader);
return a;
}
diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.cs b/Src/Newtonsoft.Json/Linq/JConstructor.cs index 296d1ae..0f8193c 100644 --- a/Src/Newtonsoft.Json/Linq/JConstructor.cs +++ b/Src/Newtonsoft.Json/Linq/JConstructor.cs @@ -185,10 +185,7 @@ namespace Newtonsoft.Json.Linq JConstructor c = new JConstructor((string)reader.Value);
c.SetLineInfo(reader as IJsonLineInfo);
- if (!reader.Read())
- throw new Exception("Error reading JConstructor from JsonReader.");
-
- c.ReadContentFrom(reader);
+ c.ReadTokenFrom(reader);
return c;
}
diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index b9704a3..8dd4ca9 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -668,6 +668,21 @@ namespace Newtonsoft.Json.Linq ClearItems();
}
+ internal void ReadTokenFrom(JsonReader r)
+ {
+ int startDepth = r.Depth;
+
+ if (!r.Read())
+ throw new Exception("Error reading {0} from JsonReader.".FormatWith(CultureInfo.InvariantCulture, GetType().Name));
+
+ ReadContentFrom(r);
+
+ int endDepth = r.Depth;
+
+ if (endDepth > startDepth)
+ throw new Exception("Unexpected end of content while loading {0}.".FormatWith(CultureInfo.InvariantCulture, GetType().Name));
+ }
+
internal void ReadContentFrom(JsonReader r)
{
ValidationUtils.ArgumentNotNull(r, "r");
diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index 8299dfa..52741bd 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -257,6 +257,7 @@ namespace Newtonsoft.Json.Linq if (!reader.Read())
throw new Exception("Error reading JObject from JsonReader.");
}
+
if (reader.TokenType != JsonToken.StartObject)
throw new Exception(
"Error reading JObject from JsonReader. Current JsonReader item is not an object: {0}".FormatWith(
@@ -265,10 +266,7 @@ namespace Newtonsoft.Json.Linq JObject o = new JObject();
o.SetLineInfo(reader as IJsonLineInfo);
- if (!reader.Read())
- throw new Exception("Error reading JObject from JsonReader.");
-
- o.ReadContentFrom(reader);
+ o.ReadTokenFrom(reader);
return o;
}
diff --git a/Src/Newtonsoft.Json/Linq/JProperty.cs b/Src/Newtonsoft.Json/Linq/JProperty.cs index d100388..845ee2f 100644 --- a/Src/Newtonsoft.Json/Linq/JProperty.cs +++ b/Src/Newtonsoft.Json/Linq/JProperty.cs @@ -260,10 +260,7 @@ namespace Newtonsoft.Json.Linq JProperty p = new JProperty((string)reader.Value);
p.SetLineInfo(reader as IJsonLineInfo);
- if (!reader.Read())
- throw new Exception("Error reading JProperty from JsonReader.");
-
- p.ReadContentFrom(reader);
+ p.ReadTokenFrom(reader);
return p;
}
|