-Added additional error checking around $ref property

This commit is contained in:
JamesNK
2010-03-17 07:27:57 +00:00
parent 6d67aefac7
commit 0b42b38f34
2 changed files with 44 additions and 0 deletions
@@ -299,9 +299,15 @@ namespace Newtonsoft.Json.Serialization
if (string.Equals(propertyName, JsonTypeReflector.RefPropertyName, StringComparison.Ordinal))
{
CheckedRead(reader);
if (reader.TokenType != JsonToken.String)
throw new JsonSerializationException("JSON reference {0} property must have a string value.".FormatWith(CultureInfo.InvariantCulture, JsonTypeReflector.RefPropertyName));
string reference = reader.Value.ToString();
CheckedRead(reader);
if (reader.TokenType == JsonToken.PropertyName)
throw new JsonSerializationException("Additional content found in JSON reference object. A JSON reference object should only have a {0} property.".FormatWith(CultureInfo.InvariantCulture, JsonTypeReflector.RefPropertyName));
return Serializer.ReferenceResolver.ResolveReference(reference);
}
else if (string.Equals(propertyName, JsonTypeReflector.TypePropertyName, StringComparison.Ordinal))