-Fixed incorrect JTokenReader.Path in certain situations
This commit is contained in:
@@ -614,5 +614,117 @@ namespace Newtonsoft.Json.Tests.Linq
|
||||
Assert.AreEqual(null, reader.ValueType);
|
||||
Assert.AreEqual(null, reader.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InitialPath_PropertyBase_PropertyToken()
|
||||
{
|
||||
JObject o = new JObject
|
||||
{
|
||||
{ "prop1", true }
|
||||
};
|
||||
|
||||
JTokenReader reader = new JTokenReader(o, "baseprop");
|
||||
|
||||
Assert.AreEqual("baseprop", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("baseprop", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("baseprop.prop1", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("baseprop.prop1", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("baseprop", reader.Path);
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
Assert.AreEqual("baseprop", reader.Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InitialPath_ArrayBase_PropertyToken()
|
||||
{
|
||||
JObject o = new JObject
|
||||
{
|
||||
{ "prop1", true }
|
||||
};
|
||||
|
||||
JTokenReader reader = new JTokenReader(o, "[0]");
|
||||
|
||||
Assert.AreEqual("[0]", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("[0]", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("[0].prop1", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("[0].prop1", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("[0]", reader.Path);
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
Assert.AreEqual("[0]", reader.Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InitialPath_PropertyBase_ArrayToken()
|
||||
{
|
||||
JArray a = new JArray
|
||||
{
|
||||
1, 2
|
||||
};
|
||||
|
||||
JTokenReader reader = new JTokenReader(a, "baseprop");
|
||||
|
||||
Assert.AreEqual("baseprop", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("baseprop", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("baseprop[0]", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("baseprop[1]", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("baseprop", reader.Path);
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
Assert.AreEqual("baseprop", reader.Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InitialPath_ArrayBase_ArrayToken()
|
||||
{
|
||||
JArray a = new JArray
|
||||
{
|
||||
1, 2
|
||||
};
|
||||
|
||||
JTokenReader reader = new JTokenReader(a, "[0]");
|
||||
|
||||
Assert.AreEqual("[0]", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("[0]", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("[0][0]", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("[0][1]", reader.Path);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual("[0]", reader.Path);
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
Assert.AreEqual("[0]", reader.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ namespace Newtonsoft.Json.Bson
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the beginning of a Json array.
|
||||
/// Writes the beginning of a JSON array.
|
||||
/// </summary>
|
||||
public override void WriteStartArray()
|
||||
{
|
||||
@@ -149,7 +149,7 @@ namespace Newtonsoft.Json.Bson
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the beginning of a Json object.
|
||||
/// Writes the beginning of a JSON object.
|
||||
/// </summary>
|
||||
public override void WriteStartObject()
|
||||
{
|
||||
@@ -159,7 +159,7 @@ namespace Newtonsoft.Json.Bson
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the property name of a name/value pair on a Json object.
|
||||
/// Writes the property name of a name/value pair on a JSON object.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
public override void WritePropertyName(string name)
|
||||
|
||||
@@ -33,7 +33,7 @@ using Newtonsoft.Json.Utilities;
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception thrown when an error occurs during Json serialization or deserialization.
|
||||
/// The exception thrown when an error occurs during JSON serialization or deserialization.
|
||||
/// </summary>
|
||||
#if !(NETFX_CORE || PORTABLE40 || PORTABLE)
|
||||
[Serializable]
|
||||
|
||||
@@ -31,7 +31,7 @@ using Newtonsoft.Json.Utilities;
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception thrown when an error occurs while reading Json text.
|
||||
/// The exception thrown when an error occurs while reading JSON text.
|
||||
/// </summary>
|
||||
#if !(NETFX_CORE || PORTABLE || PORTABLE40)
|
||||
[Serializable]
|
||||
|
||||
@@ -31,7 +31,7 @@ using System.Text;
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception thrown when an error occurs during Json serialization or deserialization.
|
||||
/// The exception thrown when an error occurs during JSON serialization or deserialization.
|
||||
/// </summary>
|
||||
#if !(NETFX_CORE || PORTABLE40 || PORTABLE)
|
||||
[Serializable]
|
||||
|
||||
@@ -374,7 +374,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how <see cref="DateTime"/> and <see cref="DateTimeOffset"/> values are formatting when writing JSON text.
|
||||
/// Get or set how <see cref="DateTime"/> and <see cref="DateTimeOffset"/> values are formatted when writing JSON text, and the expected date format when reading JSON text.
|
||||
/// </summary>
|
||||
public virtual string DateFormatString
|
||||
{
|
||||
@@ -644,7 +644,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the Json structure contained by the specified <see cref="JsonReader"/>.
|
||||
/// Deserializes the JSON structure contained by the specified <see cref="JsonReader"/>.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> that contains the JSON structure to deserialize.</param>
|
||||
/// <returns>The <see cref="Object"/> being deserialized.</returns>
|
||||
@@ -654,7 +654,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the Json structure contained by the specified <see cref="StringReader"/>
|
||||
/// Deserializes the JSON structure contained by the specified <see cref="StringReader"/>
|
||||
/// into an instance of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="TextReader"/> containing the object.</param>
|
||||
@@ -666,7 +666,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the Json structure contained by the specified <see cref="JsonReader"/>
|
||||
/// Deserializes the JSON structure contained by the specified <see cref="JsonReader"/>
|
||||
/// into an instance of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> containing the object.</param>
|
||||
@@ -678,7 +678,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes the Json structure contained by the specified <see cref="JsonReader"/>
|
||||
/// Deserializes the JSON structure contained by the specified <see cref="JsonReader"/>
|
||||
/// into an instance of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> containing the object.</param>
|
||||
@@ -810,10 +810,10 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified <see cref="Object"/> and writes the Json structure
|
||||
/// Serializes the specified <see cref="Object"/> and writes the JSON structure
|
||||
/// to a <c>Stream</c> using the specified <see cref="TextWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="textWriter">The <see cref="TextWriter"/> used to write the Json structure.</param>
|
||||
/// <param name="textWriter">The <see cref="TextWriter"/> used to write the JSON structure.</param>
|
||||
/// <param name="value">The <see cref="Object"/> to serialize.</param>
|
||||
public void Serialize(TextWriter textWriter, object value)
|
||||
{
|
||||
@@ -821,10 +821,10 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified <see cref="Object"/> and writes the Json structure
|
||||
/// Serializes the specified <see cref="Object"/> and writes the JSON structure
|
||||
/// to a <c>Stream</c> using the specified <see cref="TextWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="jsonWriter">The <see cref="JsonWriter"/> used to write the Json structure.</param>
|
||||
/// <param name="jsonWriter">The <see cref="JsonWriter"/> used to write the JSON structure.</param>
|
||||
/// <param name="value">The <see cref="Object"/> to serialize.</param>
|
||||
/// <param name="objectType">
|
||||
/// The type of the value being serialized.
|
||||
@@ -837,10 +837,10 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified <see cref="Object"/> and writes the Json structure
|
||||
/// Serializes the specified <see cref="Object"/> and writes the JSON structure
|
||||
/// to a <c>Stream</c> using the specified <see cref="TextWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="textWriter">The <see cref="TextWriter"/> used to write the Json structure.</param>
|
||||
/// <param name="textWriter">The <see cref="TextWriter"/> used to write the JSON structure.</param>
|
||||
/// <param name="value">The <see cref="Object"/> to serialize.</param>
|
||||
/// <param name="objectType">
|
||||
/// The type of the value being serialized.
|
||||
@@ -853,10 +853,10 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified <see cref="Object"/> and writes the Json structure
|
||||
/// Serializes the specified <see cref="Object"/> and writes the JSON structure
|
||||
/// to a <c>Stream</c> using the specified <see cref="JsonWriter"/>.
|
||||
/// </summary>
|
||||
/// <param name="jsonWriter">The <see cref="JsonWriter"/> used to write the Json structure.</param>
|
||||
/// <param name="jsonWriter">The <see cref="JsonWriter"/> used to write the JSON structure.</param>
|
||||
/// <param name="value">The <see cref="Object"/> to serialize.</param>
|
||||
public void Serialize(JsonWriter jsonWriter, object value)
|
||||
{
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or set how <see cref="DateTime"/> and <see cref="DateTimeOffset"/> values are formatting when writing JSON text.
|
||||
/// Get or set how <see cref="DateTime"/> and <see cref="DateTimeOffset"/> values are formatted when writing JSON text, and the expected date format when reading JSON text.
|
||||
/// </summary>
|
||||
public string DateFormatString
|
||||
{
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the beginning of a Json object.
|
||||
/// Writes the beginning of a JSON object.
|
||||
/// </summary>
|
||||
public override void WriteStartObject()
|
||||
{
|
||||
@@ -170,7 +170,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the beginning of a Json array.
|
||||
/// Writes the beginning of a JSON array.
|
||||
/// </summary>
|
||||
public override void WriteStartArray()
|
||||
{
|
||||
@@ -215,7 +215,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the property name of a name/value pair on a Json object.
|
||||
/// Writes the property name of a name/value pair on a JSON object.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
public override void WritePropertyName(string name)
|
||||
|
||||
@@ -30,7 +30,7 @@ using System.Text;
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the type of Json token.
|
||||
/// Specifies the type of JSON token.
|
||||
/// </summary>
|
||||
public enum JsonToken
|
||||
{
|
||||
|
||||
@@ -353,7 +353,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the beginning of a Json object.
|
||||
/// Writes the beginning of a JSON object.
|
||||
/// </summary>
|
||||
public virtual void WriteStartObject()
|
||||
{
|
||||
@@ -361,7 +361,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the end of a Json object.
|
||||
/// Writes the end of a JSON object.
|
||||
/// </summary>
|
||||
public virtual void WriteEndObject()
|
||||
{
|
||||
@@ -369,7 +369,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the beginning of a Json array.
|
||||
/// Writes the beginning of a JSON array.
|
||||
/// </summary>
|
||||
public virtual void WriteStartArray()
|
||||
{
|
||||
@@ -421,7 +421,7 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the end of the current Json object or array.
|
||||
/// Writes the end of the current JSON object or array.
|
||||
/// </summary>
|
||||
public virtual void WriteEnd()
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ using System.Text;
|
||||
namespace Newtonsoft.Json
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception thrown when an error occurs while reading Json text.
|
||||
/// The exception thrown when an error occurs while reading JSON text.
|
||||
/// </summary>
|
||||
#if !(NETFX_CORE || PORTABLE40 || PORTABLE)
|
||||
[Serializable]
|
||||
|
||||
@@ -348,8 +348,7 @@ namespace Newtonsoft.Json.Linq
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return _initialPath;
|
||||
|
||||
if (_initialPath.EndsWith(']')
|
||||
|| path.StartsWith('['))
|
||||
if (path.StartsWith('['))
|
||||
path = _initialPath + path;
|
||||
else
|
||||
path = _initialPath + "." + path;
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the beginning of a Json object.
|
||||
/// Writes the beginning of a JSON object.
|
||||
/// </summary>
|
||||
public override void WriteStartObject()
|
||||
{
|
||||
@@ -131,7 +131,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the beginning of a Json array.
|
||||
/// Writes the beginning of a JSON array.
|
||||
/// </summary>
|
||||
public override void WriteStartArray()
|
||||
{
|
||||
@@ -161,7 +161,7 @@ namespace Newtonsoft.Json.Linq
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the property name of a name/value pair on a Json object.
|
||||
/// Writes the property name of a name/value pair on a JSON object.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the property.</param>
|
||||
public override void WritePropertyName(string name)
|
||||
|
||||
Reference in New Issue
Block a user