-Fixed error with whitespace only JSONPath
-Fixed property query path that starts with $ -Fixed array query path with open brace after $
This commit is contained in:
@@ -1930,7 +1930,4 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -50,6 +50,46 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
[TestFixture]
|
||||
public class JPathExecuteTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void EvaluateEmptyString()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("Blah", 1));
|
||||
|
||||
JToken t = o.SelectToken("");
|
||||
Assert.AreEqual(o, t);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EvaluateWhitespaceString()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("Blah", 1));
|
||||
|
||||
JToken t = o.SelectToken(" ");
|
||||
Assert.AreEqual(o, t);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EvaluateDollarString()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("Blah", 1));
|
||||
|
||||
JToken t = o.SelectToken("$");
|
||||
Assert.AreEqual(o, t);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EvaluateDollarTypeString()
|
||||
{
|
||||
JObject o = new JObject(
|
||||
new JProperty("$values", new JArray(1, 2, 3)));
|
||||
|
||||
JToken t = o.SelectToken("$values[1]");
|
||||
Assert.AreEqual(2, (int)t);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EvaluateSingleProperty()
|
||||
{
|
||||
|
||||
@@ -141,6 +141,14 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
||||
Assert.AreEqual(null, ((ArrayIndexFilter)path.Filters[0]).Index);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RootArrayNoDot()
|
||||
{
|
||||
JPath path = new JPath("$[1]");
|
||||
Assert.AreEqual(1, path.Filters.Count);
|
||||
Assert.AreEqual(1, ((ArrayIndexFilter)path.Filters[0]).Index);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WildcardArray()
|
||||
{
|
||||
|
||||
@@ -51,21 +51,24 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
||||
{
|
||||
int currentPartStartIndex = _currentIndex;
|
||||
|
||||
if (_expression.Length == 0)
|
||||
return;
|
||||
|
||||
EatWhitespace();
|
||||
|
||||
if (_expression.Length == _currentIndex)
|
||||
return;
|
||||
|
||||
if (_expression[_currentIndex] == '$')
|
||||
{
|
||||
_currentIndex++;
|
||||
if (_expression.Length == 1)
|
||||
return;
|
||||
|
||||
EnsureLength("Unexpected end while parsing path.");
|
||||
|
||||
if (_expression[_currentIndex] != '.')
|
||||
throw new JsonException("Unexpected character while parsing path: " + _expression[_currentIndex]);
|
||||
|
||||
currentPartStartIndex = _currentIndex;
|
||||
// only increment position for "$." or "$["
|
||||
// otherwise assume property that starts with $
|
||||
char c = _expression[_currentIndex + 1];
|
||||
if (c == '.' || c == '[')
|
||||
{
|
||||
_currentIndex++;
|
||||
currentPartStartIndex = _currentIndex;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ParsePath(Filters, currentPartStartIndex, false))
|
||||
|
||||
Reference in New Issue
Block a user