-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]
|
[TestFixture]
|
||||||
public class JPathExecuteTests : TestFixtureBase
|
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]
|
[Test]
|
||||||
public void EvaluateSingleProperty()
|
public void EvaluateSingleProperty()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -141,6 +141,14 @@ namespace Newtonsoft.Json.Tests.Linq.JsonPath
|
|||||||
Assert.AreEqual(null, ((ArrayIndexFilter)path.Filters[0]).Index);
|
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]
|
[Test]
|
||||||
public void WildcardArray()
|
public void WildcardArray()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,21 +51,24 @@ namespace Newtonsoft.Json.Linq.JsonPath
|
|||||||
{
|
{
|
||||||
int currentPartStartIndex = _currentIndex;
|
int currentPartStartIndex = _currentIndex;
|
||||||
|
|
||||||
if (_expression.Length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
EatWhitespace();
|
EatWhitespace();
|
||||||
|
|
||||||
|
if (_expression.Length == _currentIndex)
|
||||||
|
return;
|
||||||
|
|
||||||
if (_expression[_currentIndex] == '$')
|
if (_expression[_currentIndex] == '$')
|
||||||
{
|
{
|
||||||
_currentIndex++;
|
if (_expression.Length == 1)
|
||||||
|
return;
|
||||||
|
|
||||||
EnsureLength("Unexpected end while parsing path.");
|
// only increment position for "$." or "$["
|
||||||
|
// otherwise assume property that starts with $
|
||||||
if (_expression[_currentIndex] != '.')
|
char c = _expression[_currentIndex + 1];
|
||||||
throw new JsonException("Unexpected character while parsing path: " + _expression[_currentIndex]);
|
if (c == '.' || c == '[')
|
||||||
|
{
|
||||||
currentPartStartIndex = _currentIndex;
|
_currentIndex++;
|
||||||
|
currentPartStartIndex = _currentIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ParsePath(Filters, currentPartStartIndex, false))
|
if (!ParsePath(Filters, currentPartStartIndex, false))
|
||||||
|
|||||||
Reference in New Issue
Block a user