Apache Lucene open-source search software
SOLR-7220: Nested C-style comments in solr queries.
Yonik Seeley40773abf6ef0
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 2857d2a2948..be2aba76448 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -185,6 +185,8 @@ New Features* SOLR-7849: Solr-managed inter-node authentication when authentication enabled (Noble Paul)+* SOLR-7220: Nested C-style comments in queries. (yonik)+Bug Fixes----------------------diff --git a/solr/core/src/java/org/apache/solr/parser/QueryParser.java b/solr/core/src/java/org/apache/solr/parser/QueryParser.javaindex 709ad00dd38..887c76bdeb2 100644--- a/solr/core/src/java/org/apache/solr/parser/QueryParser.java+++ b/solr/core/src/java/org/apache/solr/parser/QueryParser.java@@ -418,6 +418,12 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConstfinally { jj_save(0, xla); }}+ private boolean jj_3R_3() {+ if (jj_scan_token(STAR)) return true;+ if (jj_scan_token(COLON)) return true;+ return false;+ }+private boolean jj_3R_2() {if (jj_scan_token(TERM)) return true;if (jj_scan_token(COLON)) return true;@@ -434,12 +440,6 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConstreturn false;}- private boolean jj_3R_3() {- if (jj_scan_token(STAR)) return true;- if (jj_scan_token(COLON)) return true;- return false;- }-/** Generated Token Manager. */public QueryParserTokenManager token_source;/** Current token. */@@ -458,10 +458,10 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConstjj_la1_init_1();}private static void jj_la1_init_0() {- jj_la1_0 = new int[] {0x600,0x600,0x3800,0x3800,0x3fb4fe00,0x240000,0x80000,0x80000,0x3fb4c000,0x23a44000,0x400000,0x400000,0x80000,0xc000000,0x0,0x40000000,0x0,0x80000000,0x80000,0x400000,0x80000,0x2fb44000,};+ jj_la1_0 = new int[] {0x6000,0x6000,0x38000,0x38000,0xfb4fe000,0x2400000,0x800000,0x800000,0xfb4c0000,0x3a440000,0x4000000,0x4000000,0x800000,0xc0000000,0x0,0x0,0x0,0x0,0x800000,0x4000000,0x800000,0xfb440000,};}private static void jj_la1_init_1() {- jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x6,0x0,0x6,0x1,0x0,0x0,0x0,0x0,};+ jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x3,0x0,0x0,0x0,0x3,0x2,0x0,0x0,0x0,0x0,0x60,0x4,0x60,0x18,0x0,0x0,0x0,0x2,};}final private JJCalls[] jj_2_rtns = new JJCalls[1];private boolean jj_rescan = false;@@ -615,7 +615,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst/** Generate ParseException. */public ParseException generateParseException() {jj_expentries.clear();- boolean[] la1tokens = new boolean[35];+ boolean[] la1tokens = new boolean[39];if (jj_kind >= 0) {la1tokens[jj_kind] = true;jj_kind = -1;@@ -632,7 +632,7 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst}}}- for (int i = 0; i < 35; i++) {+ for (int i = 0; i < 39; i++) {if (la1tokens[i]) {jj_expentry = new int[1];jj_expentry[0] = i;diff --git a/solr/core/src/java/org/apache/solr/parser/QueryParser.jj b/solr/core/src/java/org/apache/solr/parser/QueryParser.jjindex aaa865ae27b..67446532cd8 100644--- a/solr/core/src/java/org/apache/solr/parser/QueryParser.jj+++ b/solr/core/src/java/org/apache/solr/parser/QueryParser.jj@@ -54,6 +54,10 @@ public class QueryParser extends SolrQueryParserBase {PARSER_END(QueryParser)+TOKEN_MGR_DECLS : {+ int commentNestingDepth ;+}+/* ***************** *//* Token Definitions *//* ***************** */@@ -72,10 +76,24 @@ PARSER_END(QueryParser)| <#_SQUOTED_CHAR: ( ~[ "'", "\\" ] | <_ESCAPED_CHAR> ) >}-<DEFAULT, Range> SKIP : {+<DEFAULT, COMMENT> SKIP : {+ < <_WHITESPACE>>+ | "/*" {commentNestingDepth++;} : COMMENT+ }++<COMMENT> SKIP : {+ // trying to avoid matching end-of-comment in string leads to more problems (incorrectly thinking we are in a string due+ // to the simplistic matching in this state.+ // < ("\"" (<_QUOTED_CHAR>)* "\"") >+ "*/" { commentNestingDepth -= 1; SwitchTo( commentNestingDepth==0 ? DEFAULT : COMMENT ); }+ | < ~[]>+}++<Range> SKIP : {< <_WHITESPACE>>}+<DEFAULT> TOKEN : {<AND: ("AND" | "&&") >| <OR: ("OR" | "||") >@@ -93,7 +111,7 @@ PARSER_END(QueryParser)| <FUZZY_SLOP: "~" ( (<_NUM_CHAR>)+ ( "." (<_NUM_CHAR>)+ )? )? >| <PREFIXTERM: ("*") | ( <_TERM_START_CHAR> (<_TERM_CHAR>)* "*" ) >| <WILDTERM: (<_TERM_START_CHAR> | [ "*", "?" ]) (<_TERM_CHAR> | ( [ "*", "?" ] ))* >- | <REGEXPTERM: "/" (~[ "/" ] | "\\/" )* "/" >+ | <REGEXPTERM: "/" (~["*","/"]) (~[ "/" ] | "\\/" )* "/" >| <RANGEIN_START: "[" > : Range| <RANGEEX_START: "{" > : Range// TODO: consider using token states instead of inlining SQUOTEDdiff --git a/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.java b/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.javaindex ecc4e213e38..ab7d58d9987 100644--- a/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.java+++ b/solr/core/src/java/org/apache/solr/parser/QueryParserConstants.java@@ -25,64 +25,66 @@ public interface QueryParserConstants {/** RegularExpression Id. */int _SQUOTED_CHAR = 7;/** RegularExpression Id. */- int AND = 9;+ int AND = 13;/** RegularExpression Id. */- int OR = 10;+ int OR = 14;/** RegularExpression Id. */- int NOT = 11;+ int NOT = 15;/** RegularExpression Id. */- int PLUS = 12;+ int PLUS = 16;/** RegularExpression Id. */- int MINUS = 13;+ int MINUS = 17;/** RegularExpression Id. */- int BAREOPER = 14;+ int BAREOPER = 18;/** RegularExpression Id. */- int LPAREN = 15;+ int LPAREN = 19;/** RegularExpression Id. */- int RPAREN = 16;+ int RPAREN = 20;/** RegularExpression Id. */- int COLON = 17;+ int COLON = 21;/** RegularExpression Id. */- int STAR = 18;+ int STAR = 22;/** RegularExpression Id. */- int CARAT = 19;+ int CARAT = 23;/** RegularExpression Id. */- int QUOTED = 20;+ int QUOTED = 24;/** RegularExpression Id. */- int TERM = 21;+ int TERM = 25;/** RegularExpression Id. */- int FUZZY_SLOP = 22;+ int FUZZY_SLOP = 26;/** RegularExpression Id. */- int PREFIXTERM = 23;+ int PREFIXTERM = 27;/** RegularExpression Id. */- int WILDTERM = 24;+ int WILDTERM = 28;/** RegularExpression Id. */- int REGEXPTERM = 25;+ int REGEXPTERM = 29;/** RegularExpression Id. */- int RANGEIN_START = 26;+ int RANGEIN_START = 30;/** RegularExpression Id. */- int RANGEEX_START = 27;+ int RANGEEX_START = 31;/** RegularExpression Id. */- int LPARAMS = 28;+ int LPARAMS = 32;/** RegularExpression Id. */- int NUMBER = 29;+ int NUMBER = 33;/** RegularExpression Id. */- int RANGE_TO = 30;+ int RANGE_TO = 34;/** RegularExpression Id. */- int RANGEIN_END = 31;+ int RANGEIN_END = 35;/** RegularExpression Id. */- int RANGEEX_END = 32;+ int RANGEEX_END = 36;/** RegularExpression Id. */- int RANGE_QUOTED = 33;+ int RANGE_QUOTED = 37;/** RegularExpression Id. */- int RANGE_GOOP = 34;+ int RANGE_GOOP = 38;/** Lexical state. */int Boost = 0;/** Lexical state. */int Range = 1;/** Lexical state. */- int DEFAULT = 2;+ int COMMENT = 2;+ /** Lexical state. */+ int DEFAULT = 3;/** Literal token values. */String[] tokenImage = {@@ -95,6 +97,10 @@ public interface QueryParserConstants {"<_QUOTED_CHAR>","<_SQUOTED_CHAR>","<token of kind 8>",+ "\"/*\"",+ "\"*/\"",+ "<token of kind 11>",+ "<token of kind 12>","<AND>","<OR>","<NOT>",diff --git a/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.java b/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.javaindex 00103452fea..0e6c11eaa78 100644--- a/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.java+++ b/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.java@@ -17,22 +17,33 @@ import org.apache.solr.search.QParser;/** Token Manager. */public class QueryParserTokenManager implements QueryParserConstants{+ int commentNestingDepth ;/** Debug output. */public java.io.PrintStream debugStream = System.out;/** Set debug output. */public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }-private final int jjStopStringLiteralDfa_2(int pos, long active0)+private final int jjStopStringLiteralDfa_3(int pos, long active0){switch (pos){+ case 0:+ if ((active0 & 0x80000000L) != 0L)+ return 36;+ if ((active0 & 0x200L) != 0L)+ return 31;+ if ((active0 & 0x400000L) != 0L)+ return 62;+ if ((active0 & 0x30000L) != 0L)+ return 15;+ return -1;default :return -1;}}-private final int jjStartNfa_2(int pos, long active0)+private final int jjStartNfa_3(int pos, long active0){- return jjMoveNfa_2(jjStopStringLiteralDfa_2(pos, active0), pos + 1);+ return jjMoveNfa_3(jjStopStringLiteralDfa_3(pos, active0), pos + 1);}private int jjStopAtPos(int pos, int kind){@@ -40,39 +51,59 @@ private int jjStopAtPos(int pos, int kind)jjmatchedPos = pos;return pos + 1;}-private int jjMoveStringLiteralDfa0_2()+private int jjMoveStringLiteralDfa0_3(){switch(curChar){case 40:- return jjStopAtPos(0, 15);+ return jjStopAtPos(0, 19);case 41:- return jjStopAtPos(0, 16);+ return jjStopAtPos(0, 20);case 42:- return jjStartNfaWithStates_2(0, 18, 61);+ return jjStartNfaWithStates_3(0, 22, 62);case 43:- return jjStartNfaWithStates_2(0, 12, 15);+ return jjStartNfaWithStates_3(0, 16, 15);case 45:- return jjStartNfaWithStates_2(0, 13, 15);+ return jjStartNfaWithStates_3(0, 17, 15);+ case 47:+ return jjMoveStringLiteralDfa1_3(0x200L);case 58:- return jjStopAtPos(0, 17);+ return jjStopAtPos(0, 21);case 91:- return jjStopAtPos(0, 26);+ return jjStopAtPos(0, 30);case 94:- return jjStopAtPos(0, 19);+ return jjStopAtPos(0, 23);case 123:- return jjStartNfaWithStates_2(0, 27, 35);+ return jjStartNfaWithStates_3(0, 31, 36);default :- return jjMoveNfa_2(0, 0);+ return jjMoveNfa_3(0, 0);+ }+}+private int jjMoveStringLiteralDfa1_3(long active0)+{+ try { curChar = input_stream.readChar(); }+ catch(java.io.IOException e) {+ jjStopStringLiteralDfa_3(0, active0);+ return 1;+ }+ switch(curChar)+ {+ case 42:+ if ((active0 & 0x200L) != 0L)+ return jjStopAtPos(1, 9);+ break;+ default :+ break;}+ return jjStartNfa_3(0, active0);}-private int jjStartNfaWithStates_2(int pos, int kind, int state)+private int jjStartNfaWithStates_3(int pos, int kind, int state){jjmatchedKind = kind;jjmatchedPos = pos;try { curChar = input_stream.readChar(); }catch(java.io.IOException e) { return pos + 1; }- return jjMoveNfa_2(state, pos + 1);+ return jjMoveNfa_3(state, pos + 1);}static final long[] jjbitVec0 = {0x1L, 0x0L, 0x0L, 0x0L@@ -86,10 +117,10 @@ static final long[] jjbitVec3 = {static final long[] jjbitVec4 = {0xfffefffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL};-private int jjMoveNfa_2(int startState, int curPos)+private int jjMoveNfa_3(int startState, int curPos){int startsAt = 0;- jjnewStateCnt = 61;+ jjnewStateCnt = 62;int i = 1;jjstateSet[0] = startState;int kind = 0x7fffffff;@@ -104,19 +135,19 @@ private int jjMoveNfa_2(int startState, int curPos){switch(jjstateSet[--i]){- case 61:+ case 62:case 27:if ((0xfbfffcfaffffd9ffL & l) == 0L)break;- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 0:if ((0xfbff54f8ffffd9ffL & l) != 0L){- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);}else if ((0x100002600L & l) != 0L)@@ -127,69 +158,69 @@ private int jjMoveNfa_2(int startState, int curPos)else if ((0x280200000000L & l) != 0L)jjstateSet[jjnewStateCnt++] = 15;else if (curChar == 47)- jjCheckNAddStates(0, 2);+ jjstateSet[jjnewStateCnt++] = 31;else if (curChar == 34)- jjCheckNAddStates(3, 5);+ jjCheckNAddStates(0, 2);if ((0x7bff50f8ffffd9ffL & l) != 0L){- if (kind > 21)- kind = 21;- jjCheckNAddStates(6, 10);+ if (kind > 25)+ kind = 25;+ jjCheckNAddStates(3, 7);}else if (curChar == 42){- if (kind > 23)- kind = 23;+ if (kind > 27)+ kind = 27;}else if (curChar == 33){- if (kind > 11)- kind = 11;+ if (kind > 15)+ kind = 15;}if (curChar == 38)jjstateSet[jjnewStateCnt++] = 4;break;case 4:- if (curChar == 38 && kind > 9)- kind = 9;+ if (curChar == 38 && kind > 13)+ kind = 13;break;case 5:if (curChar == 38)jjstateSet[jjnewStateCnt++] = 4;break;case 13:- if (curChar == 33 && kind > 11)- kind = 11;+ if (curChar == 33 && kind > 15)+ kind = 15;break;case 14:if ((0x280200000000L & l) != 0L)jjstateSet[jjnewStateCnt++] = 15;break;case 15:- if ((0x100002600L & l) != 0L && kind > 14)- kind = 14;+ if ((0x100002600L & l) != 0L && kind > 18)+ kind = 18;break;case 16:if (curChar == 34)- jjCheckNAddStates(3, 5);+ jjCheckNAddStates(0, 2);break;case 17:if ((0xfffffffbffffffffL & l) != 0L)- jjCheckNAddStates(3, 5);+ jjCheckNAddStates(0, 2);break;case 19:- jjCheckNAddStates(3, 5);+ jjCheckNAddStates(0, 2);break;case 20:- if (curChar == 34 && kind > 20)- kind = 20;+ if (curChar == 34 && kind > 24)+ kind = 24;break;case 22:if ((0x3ff000000000000L & l) == 0L)break;- if (kind > 22)- kind = 22;- jjAddStates(11, 12);+ if (kind > 26)+ kind = 26;+ jjAddStates(8, 9);break;case 23:if (curChar == 46)@@ -198,120 +229,127 @@ private int jjMoveNfa_2(int startState, int curPos)case 24:if ((0x3ff000000000000L & l) == 0L)break;- if (kind > 22)- kind = 22;+ if (kind > 26)+ kind = 26;jjCheckNAdd(24);break;case 25:- if (curChar == 42 && kind > 23)- kind = 23;+ if (curChar == 42 && kind > 27)+ kind = 27;break;case 26:if ((0xfbff54f8ffffd9ffL & l) == 0L)break;- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 29:- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 30:- case 32:if (curChar == 47)- jjCheckNAddStates(0, 2);+ jjstateSet[jjnewStateCnt++] = 31;break;case 31:+ if ((0xffff7bffffffffffL & l) != 0L)+ jjCheckNAddStates(10, 12);+ break;+ case 32:if ((0xffff7fffffffffffL & l) != 0L)- jjCheckNAddStates(0, 2);+ jjCheckNAddStates(10, 12);break;- case 34:- if (curChar == 47 && kind > 25)- kind = 25;+ case 33:+ if (curChar == 47)+ jjCheckNAddStates(10, 12);break;case 35:+ if (curChar == 47 && kind > 29)+ kind = 29;+ break;+ case 36:if (curChar == 33)jjCheckNAddStates(13, 15);break;- case 36:+ case 37:if ((0x100002600L & l) != 0L)- jjCheckNAddTwoStates(36, 37);+ jjCheckNAddTwoStates(37, 38);break;- case 37:+ case 38:if ((0xdfffffffffffffffL & l) != 0L)jjCheckNAddStates(16, 19);break;- case 38:+ case 39:if (curChar == 61)jjCheckNAddStates(20, 25);break;- case 39:+ case 40:if (curChar == 34)jjCheckNAddStates(26, 28);break;- case 40:+ case 41:if ((0xfffffffbffffffffL & l) != 0L)jjCheckNAddStates(26, 28);break;- case 42:+ case 43:jjCheckNAddStates(26, 28);break;- case 43:+ case 44:if (curChar == 34)jjCheckNAddStates(13, 15);break;- case 46:+ case 47:if ((0xfffffdfefffff9ffL & l) == 0L)break;- if (kind > 28)- kind = 28;- jjstateSet[jjnewStateCnt++] = 46;+ if (kind > 32)+ kind = 32;+ jjstateSet[jjnewStateCnt++] = 47;break;- case 47:+ case 48:if (curChar == 39)jjCheckNAddStates(29, 31);break;- case 48:+ case 49:if ((0xffffff7fffffffffL & l) != 0L)jjCheckNAddStates(29, 31);break;- case 50:+ case 51:jjCheckNAddStates(29, 31);break;- case 51:+ case 52:if (curChar == 39)jjCheckNAddStates(13, 15);break;- case 52:+ case 53:if ((0xfffffffeffffffffL & l) != 0L)jjCheckNAddStates(32, 35);break;- case 53:+ case 54:if ((0x7bff50f8ffffd9ffL & l) == 0L)break;- if (kind > 21)- kind = 21;- jjCheckNAddStates(6, 10);+ if (kind > 25)+ kind = 25;+ jjCheckNAddStates(3, 7);break;- case 54:+ case 55:if ((0x7bfff8faffffd9ffL & l) == 0L)break;- if (kind > 21)- kind = 21;- jjCheckNAddTwoStates(54, 55);- break;- case 56:- if (kind > 21)- kind = 21;- jjCheckNAddTwoStates(54, 55);+ if (kind > 25)+ kind = 25;+ jjCheckNAddTwoStates(55, 56);break;case 57:+ if (kind > 25)+ kind = 25;+ jjCheckNAddTwoStates(55, 56);+ break;+ case 58:if ((0x7bfff8faffffd9ffL & l) != 0L)jjCheckNAddStates(36, 38);break;- case 59:+ case 60:jjCheckNAddStates(36, 38);break;default : break;@@ -325,11 +363,11 @@ private int jjMoveNfa_2(int startState, int curPos){switch(jjstateSet[--i]){- case 61:+ case 62:if ((0x97ffffff87ffffffL & l) != 0L){- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);}else if (curChar == 92)@@ -338,24 +376,24 @@ private int jjMoveNfa_2(int startState, int curPos)case 0:if ((0x97ffffff87ffffffL & l) != 0L){- if (kind > 21)- kind = 21;- jjCheckNAddStates(6, 10);+ if (kind > 25)+ kind = 25;+ jjCheckNAddStates(3, 7);}else if (curChar == 92)jjCheckNAddStates(39, 41);else if (curChar == 123)- jjstateSet[jjnewStateCnt++] = 35;+ jjstateSet[jjnewStateCnt++] = 36;else if (curChar == 126){- if (kind > 22)- kind = 22;+ if (kind > 26)+ kind = 26;jjstateSet[jjnewStateCnt++] = 22;}if ((0x97ffffff87ffffffL & l) != 0L){- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);}if (curChar == 78)@@ -368,8 +406,8 @@ private int jjMoveNfa_2(int startState, int curPos)jjstateSet[jjnewStateCnt++] = 2;break;case 1:- if (curChar == 68 && kind > 9)- kind = 9;+ if (curChar == 68 && kind > 13)+ kind = 13;break;case 2:if (curChar == 78)@@ -380,24 +418,24 @@ private int jjMoveNfa_2(int startState, int curPos)jjstateSet[jjnewStateCnt++] = 2;break;case 6:- if (curChar == 82 && kind > 10)- kind = 10;+ if (curChar == 82 && kind > 14)+ kind = 14;break;case 7:if (curChar == 79)jjstateSet[jjnewStateCnt++] = 6;break;case 8:- if (curChar == 124 && kind > 10)- kind = 10;+ if (curChar == 124 && kind > 14)+ kind = 14;break;case 9:if (curChar == 124)jjstateSet[jjnewStateCnt++] = 8;break;case 10:- if (curChar == 84 && kind > 11)- kind = 11;+ if (curChar == 84 && kind > 15)+ kind = 15;break;case 11:if (curChar == 79)@@ -409,34 +447,34 @@ private int jjMoveNfa_2(int startState, int curPos)break;case 17:if ((0xffffffffefffffffL & l) != 0L)- jjCheckNAddStates(3, 5);+ jjCheckNAddStates(0, 2);break;case 18:if (curChar == 92)jjstateSet[jjnewStateCnt++] = 19;break;case 19:- jjCheckNAddStates(3, 5);+ jjCheckNAddStates(0, 2);break;case 21:if (curChar != 126)break;- if (kind > 22)- kind = 22;+ if (kind > 26)+ kind = 26;jjstateSet[jjnewStateCnt++] = 22;break;case 26:if ((0x97ffffff87ffffffL & l) == 0L)break;- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 27:if ((0x97ffffff87ffffffL & l) == 0L)break;- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 28:@@ -444,100 +482,101 @@ private int jjMoveNfa_2(int startState, int curPos)jjCheckNAddTwoStates(29, 29);break;case 29:- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 31:- jjAddStates(0, 2);+ case 32:+ jjCheckNAddStates(10, 12);break;- case 33:+ case 34:if (curChar == 92)- jjstateSet[jjnewStateCnt++] = 32;+ jjstateSet[jjnewStateCnt++] = 33;break;- case 37:+ case 38:if ((0xdfffffffffffffffL & l) != 0L)jjCheckNAddStates(16, 19);break;- case 40:+ case 41:if ((0xffffffffefffffffL & l) != 0L)jjCheckNAddStates(26, 28);break;- case 41:+ case 42:if (curChar == 92)- jjstateSet[jjnewStateCnt++] = 42;+ jjstateSet[jjnewStateCnt++] = 43;break;- case 42:+ case 43:jjCheckNAddStates(26, 28);break;- case 44:+ case 45:if (curChar != 125)break;- if (kind > 28)- kind = 28;- jjCheckNAddTwoStates(45, 46);+ if (kind > 32)+ kind = 32;+ jjCheckNAddTwoStates(46, 47);break;- case 45:+ case 46:if (curChar == 123)- jjstateSet[jjnewStateCnt++] = 35;+ jjstateSet[jjnewStateCnt++] = 36;break;- case 46:+ case 47:if ((0xf7ffffffbfffffffL & l) == 0L)break;- if (kind > 28)- kind = 28;- jjCheckNAdd(46);+ if (kind > 32)+ kind = 32;+ jjCheckNAdd(47);break;- case 48:+ case 49:if ((0xffffffffefffffffL & l) != 0L)jjCheckNAddStates(29, 31);break;- case 49:+ case 50:if (curChar == 92)- jjstateSet[jjnewStateCnt++] = 50;+ jjstateSet[jjnewStateCnt++] = 51;break;- case 50:+ case 51:jjCheckNAddStates(29, 31);break;- case 52:+ case 53:if ((0xdfffffffffffffffL & l) != 0L)jjCheckNAddStates(32, 35);break;- case 53:- if ((0x97ffffff87ffffffL & l) == 0L)- break;- if (kind > 21)- kind = 21;- jjCheckNAddStates(6, 10);- break;case 54:if ((0x97ffffff87ffffffL & l) == 0L)break;- if (kind > 21)- kind = 21;- jjCheckNAddTwoStates(54, 55);+ if (kind > 25)+ kind = 25;+ jjCheckNAddStates(3, 7);break;case 55:- if (curChar == 92)- jjCheckNAddTwoStates(56, 56);+ if ((0x97ffffff87ffffffL & l) == 0L)+ break;+ if (kind > 25)+ kind = 25;+ jjCheckNAddTwoStates(55, 56);break;case 56:- if (kind > 21)- kind = 21;- jjCheckNAddTwoStates(54, 55);+ if (curChar == 92)+ jjCheckNAddTwoStates(57, 57);break;case 57:+ if (kind > 25)+ kind = 25;+ jjCheckNAddTwoStates(55, 56);+ break;+ case 58:if ((0x97ffffff87ffffffL & l) != 0L)jjCheckNAddStates(36, 38);break;- case 58:+ case 59:if (curChar == 92)- jjCheckNAddTwoStates(59, 59);+ jjCheckNAddTwoStates(60, 60);break;- case 59:+ case 60:jjCheckNAddStates(36, 38);break;- case 60:+ case 61:if (curChar == 92)jjCheckNAddStates(39, 41);break;@@ -556,12 +595,12 @@ private int jjMoveNfa_2(int startState, int curPos){switch(jjstateSet[--i]){- case 61:+ case 62:case 27:if (!jjCanMove_2(hiByte, i1, i2, l1, l2))break;- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 0:@@ -572,99 +611,100 @@ private int jjMoveNfa_2(int startState, int curPos)}if (jjCanMove_2(hiByte, i1, i2, l1, l2)){- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);}if (jjCanMove_2(hiByte, i1, i2, l1, l2)){- if (kind > 21)- kind = 21;- jjCheckNAddStates(6, 10);+ if (kind > 25)+ kind = 25;+ jjCheckNAddStates(3, 7);}break;case 15:- if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 14)- kind = 14;+ if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 18)+ kind = 18;break;case 17:case 19:if (jjCanMove_1(hiByte, i1, i2, l1, l2))- jjCheckNAddStates(3, 5);+ jjCheckNAddStates(0, 2);break;case 26:if (!jjCanMove_2(hiByte, i1, i2, l1, l2))break;- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 29:if (!jjCanMove_1(hiByte, i1, i2, l1, l2))break;- if (kind > 24)- kind = 24;+ if (kind > 28)+ kind = 28;jjCheckNAddTwoStates(27, 28);break;case 31:+ case 32:if (jjCanMove_1(hiByte, i1, i2, l1, l2))- jjAddStates(0, 2);+ jjCheckNAddStates(10, 12);break;- case 36:+ case 37:if (jjCanMove_0(hiByte, i1, i2, l1, l2))- jjCheckNAddTwoStates(36, 37);+ jjCheckNAddTwoStates(37, 38);break;- case 37:+ case 38:if (jjCanMove_1(hiByte, i1, i2, l1, l2))jjCheckNAddStates(16, 19);break;- case 40:- case 42:+ case 41:+ case 43:if (jjCanMove_1(hiByte, i1, i2, l1, l2))jjCheckNAddStates(26, 28);break;- case 46:+ case 47:if (!jjCanMove_1(hiByte, i1, i2, l1, l2))break;- if (kind > 28)- kind = 28;- jjstateSet[jjnewStateCnt++] = 46;+ if (kind > 32)+ kind = 32;+ jjstateSet[jjnewStateCnt++] = 47;break;- case 48:- case 50:+ case 49:+ case 51:if (jjCanMove_1(hiByte, i1, i2, l1, l2))jjCheckNAddStates(29, 31);break;- case 52:+ case 53:if (jjCanMove_1(hiByte, i1, i2, l1, l2))jjCheckNAddStates(32, 35);break;- case 53:+ case 54:if (!jjCanMove_2(hiByte, i1, i2, l1, l2))break;- if (kind > 21)- kind = 21;- jjCheckNAddStates(6, 10);+ if (kind > 25)+ kind = 25;+ jjCheckNAddStates(3, 7);break;- case 54:+ case 55:if (!jjCanMove_2(hiByte, i1, i2, l1, l2))break;- if (kind > 21)- kind = 21;- jjCheckNAddTwoStates(54, 55);+ if (kind > 25)+ kind = 25;+ jjCheckNAddTwoStates(55, 56);break;- case 56:+ case 57:if (!jjCanMove_1(hiByte, i1, i2, l1, l2))break;- if (kind > 21)- kind = 21;- jjCheckNAddTwoStates(54, 55);+ if (kind > 25)+ kind = 25;+ jjCheckNAddTwoStates(55, 56);break;- case 57:+ case 58:if (jjCanMove_2(hiByte, i1, i2, l1, l2))jjCheckNAddStates(36, 38);break;- case 59:+ case 60:if (jjCanMove_1(hiByte, i1, i2, l1, l2))jjCheckNAddStates(36, 38);break;@@ -679,7 +719,122 @@ private int jjMoveNfa_2(int startState, int curPos)kind = 0x7fffffff;}++curPos;- if ((i = jjnewStateCnt) == (startsAt = 61 - (jjnewStateCnt = startsAt)))+ if ((i = jjnewStateCnt) == (startsAt = 62 - (jjnewStateCnt = startsAt)))+ return curPos;+ try { curChar = input_stream.readChar(); }+ catch(java.io.IOException e) { return curPos; }+ }+}+private final int jjStopStringLiteralDfa_2(int pos, long active0)+{+ switch (pos)+ {+ default :+ return -1;+ }+}+private final int jjStartNfa_2(int pos, long active0)+{+ return jjMoveNfa_2(jjStopStringLiteralDfa_2(pos, active0), pos + 1);+}+private int jjMoveStringLiteralDfa0_2()+{+ switch(curChar)+ {+ case 42:+ return jjMoveStringLiteralDfa1_2(0x400L);+ case 47:+ return jjMoveStringLiteralDfa1_2(0x200L);+ default :+ return jjMoveNfa_2(0, 0);+ }+}+private int jjMoveStringLiteralDfa1_2(long active0)+{+ try { curChar = input_stream.readChar(); }+ catch(java.io.IOException e) {+ jjStopStringLiteralDfa_2(0, active0);+ return 1;+ }+ switch(curChar)+ {+ case 42:+ if ((active0 & 0x200L) != 0L)+ return jjStopAtPos(1, 9);+ break;+ case 47:+ if ((active0 & 0x400L) != 0L)+ return jjStopAtPos(1, 10);+ break;+ default :+ break;+ }+ return jjStartNfa_2(0, active0);+}+private int jjMoveNfa_2(int startState, int curPos)+{+ int startsAt = 0;+ jjnewStateCnt = 1;+ int i = 1;+ jjstateSet[0] = startState;+ int kind = 0x7fffffff;+ for (;;)+ {+ if (++jjround == 0x7fffffff)+ ReInitRounds();+ if (curChar < 64)+ {+ long l = 1L << curChar;+ do+ {+ switch(jjstateSet[--i])+ {+ case 0:+ if ((0x100002600L & l) != 0L)+ kind = 8;+ break;+ default : break;+ }+ } while(i != startsAt);+ }+ else if (curChar < 128)+ {+ long l = 1L << (curChar & 077);+ do+ {+ switch(jjstateSet[--i])+ {+ default : break;+ }+ } while(i != startsAt);+ }+ else+ {+ int hiByte = (int)(curChar >> 8);+ int i1 = hiByte >> 6;+ long l1 = 1L << (hiByte & 077);+ int i2 = (curChar & 0xff) >> 6;+ long l2 = 1L << (curChar & 077);+ do+ {+ switch(jjstateSet[--i])+ {+ case 0:+ if (jjCanMove_0(hiByte, i1, i2, l1, l2) && kind > 8)+ kind = 8;+ break;+ default : break;+ }+ } while(i != startsAt);+ }+ if (kind != 0x7fffffff)+ {+ jjmatchedKind = kind;+ jjmatchedPos = curPos;+ kind = 0x7fffffff;+ }+ ++curPos;+ if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))return curPos;try { curChar = input_stream.readChar(); }catch(java.io.IOException e) { return curPos; }@@ -710,8 +865,8 @@ private int jjMoveNfa_0(int startState, int curPos)case 0:if ((0x3ff000000000000L & l) != 0L){- if (kind > 29)- kind = 29;+ if (kind > 33)+ kind = 33;jjCheckNAddTwoStates(2, 3);}else if (curChar == 45)@@ -726,8 +881,8 @@ private int jjMoveNfa_0(int startState, int curPos)case 2:if ((0x3ff000000000000L & l) == 0L)break;- if (kind > 29)- kind = 29;+ if (kind > 33)+ kind = 33;jjCheckNAddTwoStates(2, 3);break;case 3:@@ -737,8 +892,8 @@ private int jjMoveNfa_0(int startState, int curPos)case 4:if ((0x3ff000000000000L & l) == 0L)break;- if (kind > 29)- kind = 29;+ if (kind > 33)+ kind = 33;jjCheckNAdd(4);break;default : break;@@ -789,9 +944,9 @@ private final int jjStopStringLiteralDfa_1(int pos, long active0)switch (pos){case 0:- if ((active0 & 0x40000000L) != 0L)+ if ((active0 & 0x400000000L) != 0L){- jjmatchedKind = 34;+ jjmatchedKind = 38;return 6;}return -1;@@ -808,11 +963,11 @@ private int jjMoveStringLiteralDfa0_1()switch(curChar){case 84:- return jjMoveStringLiteralDfa1_1(0x40000000L);+ return jjMoveStringLiteralDfa1_1(0x400000000L);case 93:- return jjStopAtPos(0, 31);+ return jjStopAtPos(0, 35);case 125:- return jjStopAtPos(0, 32);+ return jjStopAtPos(0, 36);default :return jjMoveNfa_1(0, 0);}@@ -827,8 +982,8 @@ private int jjMoveStringLiteralDfa1_1(long active0)switch(curChar){case 79:- if ((active0 & 0x40000000L) != 0L)- return jjStartNfaWithStates_1(1, 30, 6);+ if ((active0 & 0x400000000L) != 0L)+ return jjStartNfaWithStates_1(1, 34, 6);break;default :break;@@ -864,14 +1019,14 @@ private int jjMoveNfa_1(int startState, int curPos)case 0:if ((0xfffffffeffffffffL & l) != 0L){- if (kind > 34)- kind = 34;+ if (kind > 38)+ kind = 38;jjCheckNAdd(6);}if ((0x100002600L & l) != 0L){- if (kind > 8)- kind = 8;+ if (kind > 12)+ kind = 12;}else if (curChar == 34)jjCheckNAddTwoStates(2, 4);@@ -889,14 +1044,14 @@ private int jjMoveNfa_1(int startState, int curPos)jjCheckNAddStates(42, 44);break;case 5:- if (curChar == 34 && kind > 33)- kind = 33;+ if (curChar == 34 && kind > 37)+ kind = 37;break;case 6:if ((0xfffffffeffffffffL & l) == 0L)break;- if (kind > 34)- kind = 34;+ if (kind > 38)+ kind = 38;jjCheckNAdd(6);break;default : break;@@ -914,8 +1069,8 @@ private int jjMoveNfa_1(int startState, int curPos)case 6:if ((0xdfffffffdfffffffL & l) == 0L)break;- if (kind > 34)- kind = 34;+ if (kind > 38)+ kind = 38;jjCheckNAdd(6);break;case 2:@@ -943,13 +1098,13 @@ private int jjMoveNfa_1(int startState, int curPos)case 0:if (jjCanMove_0(hiByte, i1, i2, l1, l2)){- if (kind > 8)- kind = 8;+ if (kind > 12)+ kind = 12;}if (jjCanMove_1(hiByte, i1, i2, l1, l2)){- if (kind > 34)- kind = 34;+ if (kind > 38)+ kind = 38;jjCheckNAdd(6);}break;@@ -960,8 +1115,8 @@ private int jjMoveNfa_1(int startState, int curPos)case 6:if (!jjCanMove_1(hiByte, i1, i2, l1, l2))break;- if (kind > 34)- kind = 34;+ if (kind > 38)+ kind = 38;jjCheckNAdd(6);break;default : break;@@ -982,9 +1137,9 @@ private int jjMoveNfa_1(int startState, int curPos)}}static final int[] jjnextStates = {- 31, 33, 34, 17, 18, 20, 54, 57, 25, 58, 55, 22, 23, 36, 37, 44,- 36, 37, 38, 44, 36, 37, 39, 47, 52, 44, 40, 41, 43, 48, 49, 51,- 36, 37, 52, 44, 57, 25, 58, 56, 59, 29, 2, 4, 5,+ 17, 18, 20, 55, 58, 25, 59, 56, 22, 23, 32, 34, 35, 37, 38, 45,+ 37, 38, 39, 45, 37, 38, 40, 48, 53, 45, 41, 42, 44, 49, 50, 52,+ 37, 38, 53, 45, 58, 25, 59, 57, 60, 29, 2, 4, 5,};private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2){@@ -1025,31 +1180,37 @@ private static final boolean jjCanMove_2(int hiByte, int i1, int i2, long l1, lo/** Token literal values. */public static final String[] jjstrLiteralImages = {-"", null, null, null, null, null, null, null, null, null, null, null, "\53",-"\55", null, "\50", "\51", "\72", "\52", "\136", null, null, null, null, null, null,-"\133", "\173", null, null, "\124\117", "\135", "\175", null, null, };+"", null, null, null, null, null, null, null, null, null, null, null, null,+null, null, null, "\53", "\55", null, "\50", "\51", "\72", "\52", "\136", null, null,+null, null, null, null, "\133", "\173", null, null, "\124\117", "\135", "\175", null,+null, };/** Lexer state names. */public static final String[] lexStateNames = {"Boost","Range",+ "COMMENT","DEFAULT",};/** Lex State array. */public static final int[] jjnewLexState = {- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1,- -1, 1, 1, -1, 2, -1, 2, 2, -1, -1,+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1,+ -1, -1, -1, -1, -1, 1, 1, -1, 3, -1, 3, 3, -1, -1,};static final long[] jjtoToken = {- 0x7fffffe01L,+ 0x7fffffe001L,};static final long[] jjtoSkip = {- 0x100L,+ 0x1f00L,};protected CharStream input_stream;-private final int[] jjrounds = new int[61];-private final int[] jjstateSet = new int[122];+private final int[] jjrounds = new int[62];+private final int[] jjstateSet = new int[124];+private final StringBuilder jjimage = new StringBuilder();+private StringBuilder image = jjimage;+private int jjimageLen;+private int lengthOfMatch;protected char curChar;/** Constructor. */public QueryParserTokenManager(CharStream stream){@@ -1074,7 +1235,7 @@ private void ReInitRounds(){int i;jjround = 0x80000001;- for (i = 61; i-- > 0;)+ for (i = 62; i-- > 0;)jjrounds[i] = 0x80000000;}@@ -1088,7 +1249,7 @@ public void ReInit(CharStream stream, int lexState)/** Switch to specified lex state. */public void SwitchTo(int lexState){- if (lexState >= 3 || lexState < 0)+ if (lexState >= 4 || lexState < 0)throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);elsecurLexState = lexState;@@ -1118,8 +1279,8 @@ protected Token jjFillToken()return t;}-int curLexState = 2;-int defaultLexState = 2;+int curLexState = 3;+int defaultLexState = 3;int jjnewStateCnt;int jjround;int jjmatchedPos;@@ -1144,6 +1305,9 @@ public Token getNextToken()matchedToken = jjFillToken();return matchedToken;}+ image = jjimage;+ image.setLength(0);+ jjimageLen = 0;switch(curLexState){@@ -1161,6 +1325,15 @@ public Token getNextToken()jjmatchedKind = 0x7fffffff;jjmatchedPos = 0;curPos = jjMoveStringLiteralDfa0_2();+ if (jjmatchedPos == 0 && jjmatchedKind > 11)+ {+ jjmatchedKind = 11;+ }+ break;+ case 3:+ jjmatchedKind = 0x7fffffff;+ jjmatchedPos = 0;+ curPos = jjMoveStringLiteralDfa0_3();break;}if (jjmatchedKind != 0x7fffffff)@@ -1176,6 +1349,7 @@ public Token getNextToken()}else{+ SkipLexicalActions(null);if (jjnewLexState[jjmatchedKind] != -1)curLexState = jjnewLexState[jjmatchedKind];continue EOFLoop;@@ -1204,6 +1378,22 @@ public Token getNextToken()}}+void SkipLexicalActions(Token matchedToken)+{+ switch(jjmatchedKind)+ {+ case 9 :+ image.append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1)));+ commentNestingDepth++;+ break;+ case 10 :+ image.append(input_stream.GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1)));+ commentNestingDepth -= 1; SwitchTo( commentNestingDepth==0 ? DEFAULT : COMMENT );+ break;+ default :+ break;+ }+}private void jjCheckNAdd(int state){if (jjrounds[state] != jjround)diff --git a/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java b/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.javaindex 5edf4419e5d..7066a6d93f3 100644--- a/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java+++ b/solr/core/src/test/org/apache/solr/search/TestSolrQueryParser.java@@ -184,4 +184,36 @@ public class TestSolrQueryParser extends SolrTestCaseJ4 {req.close();}+ @Test+ public void testComments() throws Exception {+ assertJQ(req("q","id:1 id:2 /* *:* */ id:3")+ ,"/response/numFound==3"+ );++ //+ assertJQ(req("q","id:1 /**.*/")+ ,"/response/numFound==1" // if it matches more than one, it's being treated as a regex.+ );+++ // don't match comment start in string+ assertJQ(req("q"," \"/*\" id:1 id:2 \"*/\" id:3")+ ,"/response/numFound==3"+ );++ // don't match an end of comment within a string+ // assertJQ(req("q","id:1 id:2 /* \"*/\" *:* */ id:3")+ // ,"/response/numFound==3"+ // );+ // removed this functionality - there's more of a danger to thinking we're in a string.+ // can't do it */ ......... '++ // nested comments+ assertJQ(req("q","id:1 /* id:2 /* */ /* /**/ id:3 */ id:10 */ id:11")+ ,"/response/numFound==2"+ );++ }++}