Browse Source

Fix issue #163 - Excess filter expressions should be disallowed.

pull/169/head
Kalle Stenflo 9 years ago
parent
commit
1617b3bb8d
  1. 3
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterCompiler.java
  2. 3
      json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java

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

@ -109,6 +109,9 @@ public class FilterCompiler {
opsStack.push(operatorNode); opsStack.push(operatorNode);
break; break;
default: default:
if(expStack.size() > 0 && opsStack.isEmpty()){
throw new InvalidPathException("Expected logical operator (&&, ||) to follow expression " + expStack.peek().toString());
}
RelationalExpressionNode relationalExpressionNode = readExpression(); RelationalExpressionNode relationalExpressionNode = readExpression();
expStack.push(relationalExpressionNode); expStack.push(relationalExpressionNode);
break; break;

3
json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java

@ -72,6 +72,7 @@ public class FilterCompilerTest {
assertInvalidPathException("[?(@ == 'foo )]"); assertInvalidPathException("[?(@ == 'foo )]");
assertInvalidPathException("[?(@ == 1' )]"); assertInvalidPathException("[?(@ == 1' )]");
assertInvalidPathException("[?(@.foo bar == 1)]"); assertInvalidPathException("[?(@.foo bar == 1)]");
assertInvalidPathException("[?(@.i == 5 @.i == 8)]");
} }
@ -80,7 +81,7 @@ public class FilterCompilerTest {
compile(filter); compile(filter);
throw new AssertionError("Expected " + filter + " to throw InvalidPathException"); throw new AssertionError("Expected " + filter + " to throw InvalidPathException");
} catch (InvalidPathException e){ } catch (InvalidPathException e){
//e.printStackTrace(); e.printStackTrace();
} }
} }
} }

Loading…
Cancel
Save