-Fixed jsonpath error when parsing a property that follows an escaped property

-Changed reader/writer/token path to escape property names containing special characters
This commit is contained in:
James Newton-King
2014-10-18 15:36:42 +13:00
parent 01f1c5e261
commit 88a29704da
12 changed files with 385 additions and 287 deletions
+14 -1
View File
@@ -41,6 +41,8 @@ namespace Newtonsoft.Json
internal struct JsonPosition
{
private static readonly char[] SpecialCharacters = {'.', ' ', '[', ']', '(', ')'};
internal JsonContainerType Type;
internal int Position;
internal string PropertyName;
@@ -61,7 +63,18 @@ namespace Newtonsoft.Json
case JsonContainerType.Object:
if (sb.Length > 0)
sb.Append('.');
sb.Append(PropertyName);
string propertyName = PropertyName;
if (propertyName.IndexOfAny(SpecialCharacters) != -1)
{
sb.Append(@"['");
sb.Append(propertyName);
sb.Append(@"']");
}
else
{
sb.Append(propertyName);
}
break;
case JsonContainerType.Array:
case JsonContainerType.Constructor: