Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions parser/src/main/java/dev/cel/parser/PrattParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private boolean expect(Lexer.TokenType type, String msg) {
nextToken();
return true;
}
if (isRecoveryLimitExceeded()) {
if (recursionLimitExceeded || isRecoveryLimitExceeded()) {
return false;
}
if (peekToken.type != Lexer.TokenType.ERROR) {
Expand All @@ -274,7 +274,7 @@ private boolean expect(Lexer.TokenType type, String msg) {

// Find the next delimiter to prevent a cascade of spurious secondary errors.
private void synchronizeOnDelimiter() {
if (isRecoveryLimitExceeded()) {
if (recursionLimitExceeded || isRecoveryLimitExceeded()) {
peekToken = END_TOKEN;
return;
}
Expand Down Expand Up @@ -412,6 +412,7 @@ private void reportRecursionLimit(int position) {
LOCALE,
"Expression recursion limit exceeded. limit: %d",
options.maxParseRecursionDepth()));
peekToken = END_TOKEN;
}
}

Expand All @@ -433,7 +434,7 @@ private CelExpr parseExpr() {
private CelExpr parseBinaryAndTernary(int minPrec) {
CelExpr lhs = parseSelectorChain();
int chainDepth = currentLhsDepth;
while (true) {
while (!recursionLimitExceeded && !isRecoveryLimitExceeded()) {
Lexer.TokenType tok = peekToken.type;
if (tok == Lexer.TokenType.QUESTION && minPrec <= 0) {
lhs = parseTernary(lhs);
Expand Down
9 changes: 8 additions & 1 deletion parser/src/test/java/dev/cel/parser/CelParserImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,14 @@ private enum MaxParseRecursionDepthTestCase {
+ " a[1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20] !="
+ " a[1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20] !="
+ " a[1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20] !="
+ " a[1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20]");
+ " a[1][2][3][4][5][6][7][8][9][10][11][12][13][14][15][16][17][18][19][20]"),
TERNARY(
"a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : a ? b :"
+ " a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : a ? b :"
+ " a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : a ? b :"
+ " a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : a ? b : c"),
TERNARY_TRUE_BRANCH_PARENS(
"a ? ((((((((((((((((((((((((((((((((b)))))))))))))))))))))))))))))))) : c");

static final int MAX_RECURSION_LIMIT = 32;
final String source;
Expand Down
9 changes: 0 additions & 9 deletions parser/src/test/resources/parser_errors.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,6 @@ E/A: Expression recursion limit exceeded. limit: 250
E/P: ERROR: <input>:1:251: Expression recursion limit exceeded. limit: 250
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['too many']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
| ..........................................................................................................................................................................................................................................................^
ERROR: <input>:1:251: Syntax error: expected ']'
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['too many']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
| ..........................................................................................................................................................................................................................................................^

I: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
»»»[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['too many']]]]]]]]]]]]]]]]]]]]]]]]]]]]
Expand All @@ -1110,19 +1107,13 @@ E/A: Expression recursion limit exceeded. limit: 32
E/P: ERROR: <input>:1:33: Expression recursion limit exceeded. limit: 32
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
| ................................^
ERROR: <input>:1:33: Syntax error: expected ']'
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
| ................................^

I: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['not fine']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
=====>
E/A: Expression recursion limit exceeded. limit: 32
E/P: ERROR: <input>:1:33: Expression recursion limit exceeded. limit: 32
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['not fine']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
| ................................^
ERROR: <input>:1:33: Syntax error: expected ']'
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['not fine']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
| ................................^

I: a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.A.B.C.D.E.F.G.H
=====>
Expand Down
6 changes: 0 additions & 6 deletions parser/src/test/resources/pratt_parser_errors.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,12 @@ I: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
E: ERROR: <input>:1:33: Expression recursion limit exceeded. limit: 32
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
| ................................^
ERROR: <input>:1:33: Syntax error: expected ']'
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
| ................................^

I: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['not fine']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
=====>
E: ERROR: <input>:1:33: Expression recursion limit exceeded. limit: 32
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['not fine']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
| ................................^
ERROR: <input>:1:33: Syntax error: expected ']'
| [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[['not fine']]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
| ................................^

I: a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.A.B.C.D.E.F.G.H
=====>
Expand Down
Loading