Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 16303e9

Browse files
committed
Fix precedence of negation vs comparison
1 parent fb01569 commit 16303e9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

jmespath-core/src/main/antlr4/io/burt/jmespath/parser/JmesPath.g4

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ expression
66
: expression '.' chainedExpression # chainExpression
77
| expression bracketSpecifier # bracketedExpression
88
| bracketSpecifier # bracketExpression
9-
| expression COMPARATOR expression # comparisonExpression
109
| '!' expression # notExpression
10+
| expression COMPARATOR expression # comparisonExpression
1111
| expression '&&' expression # andExpression
1212
| expression '||' expression # orExpression
1313
| identifier # identifierExpression

jmespath-core/src/main/java/io/burt/jmespath/node/NegateNode.java

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ protected boolean internalEquals(Object o) {
2222
return negated.equals(other.negated);
2323
}
2424

25+
@Override
26+
protected String internalToString() {
27+
return negated.toString();
28+
}
29+
2530
@Override
2631
protected int internalHashCode() {
2732
return 17 + 31 * negated.hashCode();

jmespath-core/src/test/java/io/burt/jmespath/parser/ParserTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,17 @@ public void negatedSelectionExpression() {
843843
assertThat(actual, is(expected));
844844
}
845845

846+
@Test
847+
public void negatedComparison() {
848+
Expression<Object> expected = Comparison(
849+
"==",
850+
Negate(Property("foo")),
851+
JsonLiteral("false")
852+
);
853+
Expression<Object> actual = compile("!foo == `false`");
854+
assertThat(actual, is(expected));
855+
}
856+
846857
@Test
847858
public void bareJsonLiteralExpression() {
848859
Expression<Object> expected = JsonLiteral("{}");

0 commit comments

Comments
 (0)