Browse Source

Fix issue #175 - Size evaluation could break indefinite path evaluation

pull/177/head
Alexey Makeyev 9 years ago
parent
commit
58c454b52d
  1. 3
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/EvaluatorFactory.java
  2. 5
      json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java

3
json-path/src/main/java/com/jayway/jsonpath/internal/filter/EvaluatorFactory.java

@ -138,6 +138,9 @@ public class EvaluatorFactory {
private static class SizeEvaluator implements Evaluator { private static class SizeEvaluator implements Evaluator {
@Override @Override
public boolean evaluate(ValueNode left, ValueNode right, Predicate.PredicateContext ctx) { public boolean evaluate(ValueNode left, ValueNode right, Predicate.PredicateContext ctx) {
if (! right.isNumberNode()) {
return false;
}
int expectedSize = right.asNumberNode().getNumber().intValue(); int expectedSize = right.asNumberNode().getNumber().intValue();
if(left.isStringNode()){ if(left.isStringNode()){

5
json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java

@ -209,4 +209,9 @@ public class InlineFilterTest extends BaseTest {
public void escape_pattern() { public void escape_pattern() {
assertHasOneResult("[\"x\"]", "$[?(@ =~ /\\/|x/)]", conf); assertHasOneResult("[\"x\"]", "$[?(@ =~ /\\/|x/)]", conf);
} }
@Test
public void filter_evaluation_does_not_break_path_evaluation() {
assertHasOneResult("[{\"s\": \"fo\", \"expected_size\": \"m\"}, {\"s\": \"lo\", \"expected_size\": 2}]", "$[?(@.s size @.expected_size)]", conf);
}
} }

Loading…
Cancel
Save