-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:
@@ -184,6 +184,55 @@ undefined
|
||||
Assert.AreEqual("person.$id", idProperty.Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EscapedPath()
|
||||
{
|
||||
string json = @"{
|
||||
""frameworks"": {
|
||||
""aspnetcore50"": {
|
||||
""dependencies"": {
|
||||
""System.Xml.ReaderWriter"": {
|
||||
""source"": ""NuGet""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
JObject o = JObject.Parse(json);
|
||||
|
||||
JToken v1 = o["frameworks"]["aspnetcore50"]["dependencies"]["System.Xml.ReaderWriter"]["source"];
|
||||
|
||||
Console.WriteLine(v1.Path);
|
||||
|
||||
JToken v2 = o.SelectToken(v1.Path);
|
||||
|
||||
Assert.AreEqual(v1, v2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EscapedPathTests()
|
||||
{
|
||||
EscapedPathAssert("this has spaces", "['this has spaces']");
|
||||
EscapedPathAssert("(RoundBraces)", "['(RoundBraces)']");
|
||||
EscapedPathAssert("[SquareBraces]", "['[SquareBraces]']");
|
||||
EscapedPathAssert("this.has.dots", "['this.has.dots']");
|
||||
}
|
||||
|
||||
private void EscapedPathAssert(string propertyName, string expectedPath)
|
||||
{
|
||||
int v1 = int.MaxValue;
|
||||
JValue value = new JValue(v1);
|
||||
|
||||
JObject o = new JObject(new JProperty(propertyName, value));
|
||||
|
||||
Assert.AreEqual(expectedPath, value.Path);
|
||||
|
||||
JValue selectedValue = (JValue)o.SelectToken(value.Path);
|
||||
|
||||
Assert.AreEqual(value, selectedValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ForEach()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user