From 8d114f058dcc03a5c3357435767402f04ac9797f Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Tue, 14 Jun 2016 12:49:08 -0400 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6325 Fix issue with selector parser. (cherry picked from commit 7b207567d9d304facdfa7c1c5d7fa8a81b6fe70e) --- .../src/main/grammar/SelectorParser.jj | 386 +++++++++--------- .../activemq/selector/SelectorTest.java | 6 +- 2 files changed, 197 insertions(+), 195 deletions(-) diff --git a/activemq-client/src/main/grammar/SelectorParser.jj b/activemq-client/src/main/grammar/SelectorParser.jj index 91a46fbe5a..6ccb113176 100755 --- a/activemq-client/src/main/grammar/SelectorParser.jj +++ b/activemq-client/src/main/grammar/SelectorParser.jj @@ -21,7 +21,7 @@ options { STATIC = false; UNICODE_INPUT = true; - + // some performance optimizations ERROR_REPORTING = false; } @@ -59,9 +59,9 @@ import org.apache.activemq.filter.*; import org.apache.activemq.filter.FunctionCallExpression.invalidFunctionExpressionException; import org.apache.activemq.util.LRUCache; -/** +/** * JMS Selector Parser generated by JavaCC - * + * * Do not edit this .java file directly - it is autogenerated from SelectorParser.jj */ public class SelectorParser { @@ -180,8 +180,8 @@ TOKEN [IGNORE_CASE] : < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* (["l","L"])? > | < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > - | < OCTAL_LITERAL: "0" (["0"-"7"])* > - | < FLOATING_POINT_LITERAL: + | < OCTAL_LITERAL: "0" (["0"-"7"])* > + | < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* ()? // matches: 5.5 or 5. or 5.5E10 or 5.E10 | "." (["0"-"9"])+ ()? // matches: .5 or .5E10 | (["0"-"9"])+ // matches: 5E10 @@ -204,8 +204,8 @@ BooleanExpression JmsSelector() : } { ( - left = orExpression() - ) + left = orExpression() + ) { return asBooleanExpression(left); } @@ -219,14 +219,14 @@ Expression orExpression() : } { ( - left = andExpression() - ( - right = andExpression() + left = andExpression() + ( + right = andExpression() { left = LogicExpression.createOR(asBooleanExpression(left), asBooleanExpression(right)); } )* - ) + ) { return left; } @@ -241,14 +241,14 @@ Expression andExpression() : } { ( - left = equalityExpression() - ( - right = equalityExpression() + left = equalityExpression() + ( + right = equalityExpression() { left = LogicExpression.createAND(asBooleanExpression(left), asBooleanExpression(right)); } )* - ) + ) { return left; } @@ -261,31 +261,31 @@ Expression equalityExpression() : } { ( - left = comparisonExpression() - ( - - "=" right = comparisonExpression() + left = comparisonExpression() + ( + + "=" right = comparisonExpression() { left = ComparisonExpression.createEqual(left, right); } - | - "<>" right = comparisonExpression() + | + "<>" right = comparisonExpression() { left = ComparisonExpression.createNotEqual(left, right); } - | + | LOOKAHEAD(2) { left = ComparisonExpression.createIsNull(left); } - | + | { left = ComparisonExpression.createIsNotNull(left); } )* - ) + ) { return left; } @@ -298,106 +298,106 @@ Expression comparisonExpression() : Expression low; Expression high; String t, u; - boolean not; - ArrayList list; + boolean not; + ArrayList list; } { ( - left = addExpression() - ( - - ">" right = addExpression() + left = addExpression() + ( + + ">" right = addExpression() { left = ComparisonExpression.createGreaterThan(left, right); } - | - ">=" right = addExpression() + | + ">=" right = addExpression() { left = ComparisonExpression.createGreaterThanEqual(left, right); } - | - "<" right = addExpression() + | + "<" right = addExpression() { left = ComparisonExpression.createLessThan(left, right); } - | - "<=" right = addExpression() + | + "<=" right = addExpression() { left = ComparisonExpression.createLessThanEqual(left, right); } | - { - u=null; - } - t = stringLitteral() - [ u = stringLitteral() ] - { + { + u=null; + } + t = stringLitteral() + [ u = stringLitteral() ] + { left = ComparisonExpression.createLike(left, t, u); - } + } | - LOOKAHEAD(2) - { - u=null; - } - t = stringLitteral() [ u = stringLitteral() ] - { + LOOKAHEAD(2) + { + u=null; + } + t = stringLitteral() [ u = stringLitteral() ] + { left = ComparisonExpression.createNotLike(left, t, u); - } + } | - low = addExpression() high = addExpression() - { - left = ComparisonExpression.createBetween(left, low, high); - } - | - LOOKAHEAD(2) - low = addExpression() high = addExpression() - { - left = ComparisonExpression.createNotBetween(left, low, high); - } + low = addExpression() high = addExpression() + { + left = ComparisonExpression.createBetween(left, low, high); + } | - - "(" - t = stringLitteral() - { - list = new ArrayList(); - list.add( t ); - } - ( - "," - t = stringLitteral() - { - list.add( t ); - } - - )* - ")" - { - left = ComparisonExpression.createInFilter(left, list); - } + LOOKAHEAD(2) + low = addExpression() high = addExpression() + { + left = ComparisonExpression.createNotBetween(left, low, high); + } | - LOOKAHEAD(2) - - "(" - t = stringLitteral() - { - list = new ArrayList(); - list.add( t ); - } - ( - "," - t = stringLitteral() - { - list.add( t ); - } - - )* - ")" - { - left = ComparisonExpression.createNotInFilter(left, list); - } - + + "(" + t = stringLitteral() + { + list = new ArrayList(); + list.add( t ); + } + ( + "," + t = stringLitteral() + { + list.add( t ); + } + + )* + ")" + { + left = ComparisonExpression.createInFilter(left, list); + } + | + LOOKAHEAD(2) + + "(" + t = stringLitteral() + { + list = new ArrayList(); + list.add( t ); + } + ( + "," + t = stringLitteral() + { + list.add( t ); + } + + )* + ")" + { + left = ComparisonExpression.createNotInFilter(left, list); + } + )* - ) + ) { return left; } @@ -409,21 +409,21 @@ Expression addExpression() : Expression right; } { - left = multExpr() - ( - LOOKAHEAD( ("+"|"-") multExpr()) - ( - "+" right = multExpr() - { - left = ArithmeticExpression.createPlus(left, right); - } - | - "-" right = multExpr() - { - left = ArithmeticExpression.createMinus(left, right); - } + left = multExpr() + ( + LOOKAHEAD( ("+"|"-") multExpr()) + ( + "+" right = multExpr() + { + left = ArithmeticExpression.createPlus(left, right); + } + | + "-" right = multExpr() + { + left = ArithmeticExpression.createMinus(left, right); + } ) - + )* { return left; @@ -436,23 +436,23 @@ Expression multExpr() : Expression right; } { - left = unaryExpr() - ( - "*" right = unaryExpr() + left = unaryExpr() + ( + "*" right = unaryExpr() { - left = ArithmeticExpression.createMultiply(left, right); + left = ArithmeticExpression.createMultiply(left, right); } - | - "/" right = unaryExpr() + | + "/" right = unaryExpr() { - left = ArithmeticExpression.createDivide(left, right); + left = ArithmeticExpression.createDivide(left, right); } - | - "%" right = unaryExpr() + | + "%" right = unaryExpr() { - left = ArithmeticExpression.createMod(left, right); + left = ArithmeticExpression.createMod(left, right); } - + )* { return left; @@ -466,34 +466,34 @@ Expression unaryExpr() : Expression left=null; } { - ( - LOOKAHEAD( "+" unaryExpr() ) - "+" left=unaryExpr() - | - "-" left=unaryExpr() - { - left = UnaryExpression.createNegate(left); - } - | - left=unaryExpr() - { - left = UnaryExpression.createNOT( asBooleanExpression(left) ); - } - | - s=stringLitteral() - { - left = UnaryExpression.createXPath( s ); - } - | - s=stringLitteral() - { - left = UnaryExpression.createXQuery( s ); - } - | + ( + LOOKAHEAD( "+" unaryExpr() ) + "+" left=unaryExpr() + | + "-" left=unaryExpr() + { + left = UnaryExpression.createNegate(left); + } + | + left=unaryExpr() + { + left = UnaryExpression.createNOT( asBooleanExpression(left) ); + } + | + s=stringLitteral() + { + left = UnaryExpression.createXPath( s ); + } + | + s=stringLitteral() + { + left = UnaryExpression.createXQuery( s ); + } + | LOOKAHEAD( "(" ) left = functionCallExpr() - | - left = primaryExpr() + | + left = primaryExpr() ) { return left; @@ -519,7 +519,7 @@ Expression functionCallExpr () : "," arg = unaryExpr() { - arg_list.add(arg); + arg_list.add(arg); } ) * ) @@ -548,7 +548,7 @@ Expression primaryExpr() : left = variable() | "(" left = orExpression() ")" - ) + ) { return left; } @@ -569,55 +569,55 @@ ConstantExpression literal() : { left = new ConstantExpression(s); } - ) - | + ) + | ( t = { - left = ConstantExpression.createFromDecimal(t.image); - } - ) - | + left = ConstantExpression.createFromDecimal(t.image); + } + ) + | ( t = { - left = ConstantExpression.createFromHex(t.image); - } - ) - | + left = ConstantExpression.createFromHex(t.image); + } + ) + | ( t = { - left = ConstantExpression.createFromOctal(t.image); - } - ) - | + left = ConstantExpression.createFromOctal(t.image); + } + ) + | ( t = { - left = ConstantExpression.createFloat(t.image); - } - ) - | + left = ConstantExpression.createFloat(t.image); + } + ) + | ( { left = ConstantExpression.TRUE; - } - ) - | + } + ) + | ( { left = ConstantExpression.FALSE; - } - ) - | + } + ) + | ( { left = ConstantExpression.NULL; - } + } ) ) { @@ -632,18 +632,18 @@ String stringLitteral() : boolean first=true; } { - t = + t = { - // Decode the sting value. - String image = t.image; - for( int i=1; i < image.length()-1; i++ ) { - char c = image.charAt(i); - if( c == '\'' ) - i++; - rc.append(c); - } - return rc.toString(); - } + // Decode the sting value. + String image = t.image; + for( int i=1; i < image.length()-1; i++ ) { + char c = image.charAt(i); + if( c == '\'' ) + i++; + rc.append(c); + } + return rc.toString(); + } } PropertyExpression variable() : @@ -652,11 +652,11 @@ PropertyExpression variable() : PropertyExpression left=null; } { - ( - t = + ( + t = { left = new PropertyExpression(t.image); - } + } ) { return left; diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/selector/SelectorTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/selector/SelectorTest.java index 8279ae4852..878498b62c 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/selector/SelectorTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/selector/SelectorTest.java @@ -20,14 +20,14 @@ import javax.jms.InvalidSelectorException; import javax.jms.JMSException; import javax.jms.Message; -import junit.framework.TestCase; - import org.apache.activemq.command.ActiveMQMessage; import org.apache.activemq.command.ActiveMQTextMessage; import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.filter.BooleanExpression; import org.apache.activemq.filter.MessageEvaluationContext; +import junit.framework.TestCase; + /** * */ @@ -327,6 +327,8 @@ public class SelectorTest extends TestCase { assertInvalidSelector(message, "3+5"); assertInvalidSelector(message, "True AND 3+5"); assertInvalidSelector(message, "=TEST 'test'"); + assertInvalidSelector(message, "prop1 = prop2 foo AND string = 'Test'"); + assertInvalidSelector(message, "a = 1 AMD b = 2"); } public void testFunctionSelector() throws Exception {