This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 3b1b9d3400a694ee8a21d78d07d85d95a55e23f2 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Sep 30 10:19:08 2021 +0100 Fix parsing bug for literal Maps constructed using variables. --- java/org/apache/el/parser/ELParser.java | 164 +++++++++++++++++++++++--- java/org/apache/el/parser/ELParser.jjt | 2 +- test/org/apache/el/parser/TestAstMapData.java | 15 +++ webapps/docs/changelog.xml | 5 + 4 files changed, 166 insertions(+), 20 deletions(-) diff --git a/java/org/apache/el/parser/ELParser.java b/java/org/apache/el/parser/ELParser.java index f35e78c..def7211 100644 --- a/java/org/apache/el/parser/ELParser.java +++ b/java/org/apache/el/parser/ELParser.java @@ -1783,7 +1783,7 @@ if (jjtc000) { } default: jj_la1[40] = jj_gen; - if (jj_2_8(3)) { + if (jj_2_8(5)) { SetData(); } else { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { @@ -2373,6 +2373,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Equality_182_5_40()) { + return true; + } return false; } @@ -2397,11 +2400,28 @@ if (jjtc000) { return false; } + private boolean jj_3R_ListData_350_26_109() + { + if (jj_scan_token(COMMA)) { + return true; + } + if (jj_3R_Expression_99_5_36()) { + return true; + } + return false; + } + private boolean jj_3R_MapEntry_368_5_107() { if (jj_3R_Expression_99_5_36()) { return true; } + if (jj_scan_token(COLON)) { + return true; + } + if (jj_3R_Expression_99_5_36()) { + return true; + } return false; } @@ -2442,6 +2462,9 @@ if (jjtc000) { if (jj_scan_token(COMMA)) { return true; } + if (jj_3R_Expression_99_5_36()) { + return true; + } return false; } @@ -2455,6 +2478,9 @@ if (jjtc000) { return true; } } + if (jj_3R_And_173_5_34()) { + return true; + } return false; } @@ -2479,6 +2505,11 @@ if (jjtc000) { if (jj_3R_Expression_99_5_36()) { return true; } + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_ListData_350_26_109()) { jj_scanpos = xsp; break; } + } return false; } @@ -2572,6 +2603,14 @@ if (jjtc000) { return false; } + private boolean jj_3R_MethodParameters_317_31_111() + { + if (jj_scan_token(COMMA)) { + return true; + } + return false; + } + private boolean jj_3R_SetData_342_5_25() { if (jj_scan_token(START_SET_OR_MAP)) { @@ -2712,12 +2751,28 @@ if (jjtc000) { if (jj_3R_Expression_99_5_36()) { return true; } + if (jj_scan_token(RPAREN)) { + return true; + } return false; } - private boolean jj_3_6() + private boolean jj_3R_MethodParameters_317_16_110() { - if (jj_3R_LambdaExpressionOrInvocation_141_5_23()) { + if (jj_3R_Expression_99_5_36()) { + return true; + } + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_MethodParameters_317_31_111()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_ValueSuffix_291_41_108() + { + if (jj_3R_MethodParameters_317_5_106()) { return true; } return false; @@ -2751,6 +2806,14 @@ if (jjtc000) { return false; } + private boolean jj_3_6() + { + if (jj_3R_LambdaExpressionOrInvocation_141_5_23()) { + return true; + } + return false; + } + private boolean jj_3R_LambdaParameters_132_5_32() { if (jj_3R_Identifier_377_5_38()) { @@ -2788,6 +2851,14 @@ if (jjtc000) { if (jj_scan_token(LPAREN)) { return true; } + Token xsp; + xsp = jj_scanpos; + if (jj_3R_MethodParameters_317_16_110()) { + jj_scanpos = xsp; + } + if (jj_scan_token(RPAREN)) { + return true; + } return false; } @@ -2815,6 +2886,9 @@ if (jjtc000) { if (jj_scan_token(SEMICOLON)) { return true; } + if (jj_3R_Assignment_115_5_20()) { + return true; + } return false; } @@ -2823,6 +2897,20 @@ if (jjtc000) { if (jj_scan_token(LBRACK)) { return true; } + if (jj_3R_Expression_99_5_36()) { + return true; + } + if (jj_scan_token(RBRACK)) { + return true; + } + return false; + } + + private boolean jj_3R_ValueSuffix_291_21_79() + { + if (jj_3R_BracketSuffix_309_5_91()) { + return true; + } return false; } @@ -2839,14 +2927,6 @@ if (jjtc000) { return false; } - private boolean jj_3R_ValueSuffix_291_21_79() - { - if (jj_3R_BracketSuffix_309_5_91()) { - return true; - } - return false; - } - private boolean jj_3_2() { if (jj_3R_LambdaExpression_124_5_21()) { @@ -2873,6 +2953,9 @@ if (jjtc000) { if (jj_scan_token(DOT)) { return true; } + if (jj_scan_token(IDENTIFIER)) { + return true; + } return false; } @@ -2907,6 +2990,10 @@ if (jjtc000) { return true; } } + xsp = jj_scanpos; + if (jj_3R_ValueSuffix_291_41_108()) { + jj_scanpos = xsp; + } return false; } @@ -3059,6 +3146,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Unary_257_9_59()) { + return true; + } return false; } @@ -3080,6 +3170,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Unary_257_9_59()) { + return true; + } return false; } @@ -3104,6 +3197,9 @@ if (jjtc000) { if (jj_scan_token(MULT)) { return true; } + if (jj_3R_Unary_257_9_59()) { + return true; + } return false; } @@ -3133,6 +3229,9 @@ if (jjtc000) { if (jj_scan_token(MINUS)) { return true; } + if (jj_3R_Multiplication_241_5_57()) { + return true; + } return false; } @@ -3162,6 +3261,9 @@ if (jjtc000) { if (jj_scan_token(PLUS)) { return true; } + if (jj_3R_Multiplication_241_5_57()) { + return true; + } return false; } @@ -3220,6 +3322,9 @@ if (jjtc000) { if (jj_scan_token(CONCAT)) { return true; } + if (jj_3R_Math_227_5_51()) { + return true; + } return false; } @@ -3244,6 +3349,17 @@ if (jjtc000) { if (jj_scan_token(COLON)) { return true; } + if (jj_scan_token(IDENTIFIER)) { + return true; + } + return false; + } + + private boolean jj_3R_Literal_408_5_80() + { + if (jj_3R_Boolean_421_5_92()) { + return true; + } return false; } @@ -3269,14 +3385,6 @@ if (jjtc000) { return false; } - private boolean jj_3R_Literal_408_5_80() - { - if (jj_3R_Boolean_421_5_92()) { - return true; - } - return false; - } - private boolean jj_3R_Concatenation_215_6_47() { if (jj_3R_Math_227_5_51()) { @@ -3308,6 +3416,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Concatenation_215_6_47()) { + return true; + } return false; } @@ -3321,6 +3432,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Concatenation_215_6_47()) { + return true; + } return false; } @@ -3334,6 +3448,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Concatenation_215_6_47()) { + return true; + } return false; } @@ -3366,6 +3483,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Concatenation_215_6_47()) { + return true; + } return false; } @@ -3412,6 +3532,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Compare_196_5_44()) { + return true; + } return false; } @@ -3438,6 +3561,9 @@ if (jjtc000) { return true; } } + if (jj_3R_Compare_196_5_44()) { + return true; + } return false; } diff --git a/java/org/apache/el/parser/ELParser.jjt b/java/org/apache/el/parser/ELParser.jjt index 5bca021..4a680dd 100644 --- a/java/org/apache/el/parser/ELParser.jjt +++ b/java/org/apache/el/parser/ELParser.jjt @@ -327,7 +327,7 @@ void NonLiteral() : {} | <LPAREN> Expression() <RPAREN> | LOOKAHEAD((<IDENTIFIER> <COLON>)? <IDENTIFIER> <LPAREN>) Function() | Identifier() - | LOOKAHEAD(3)SetData() + | LOOKAHEAD(5)SetData() | ListData() | MapData() } diff --git a/test/org/apache/el/parser/TestAstMapData.java b/test/org/apache/el/parser/TestAstMapData.java index 32a8876..9b5082f 100644 --- a/test/org/apache/el/parser/TestAstMapData.java +++ b/test/org/apache/el/parser/TestAstMapData.java @@ -87,4 +87,19 @@ public class TestAstMapData { Assert.assertEquals(Map.class, ve.getType(context)); Assert.assertEquals(simpleMap, ve.getValue(context)); } + + + @Test + public void testLiteralWithVariable() { + ELProcessor elp = new ELProcessor(); + + String key = "myKey"; + String value = "myValue"; + elp.setVariable("aaa", "'" + key + "'"); + elp.setVariable("bbb", "'" + value + "'"); + + Object result = elp.eval("{ aaa : bbb }.get(aaa)"); + + Assert.assertEquals(value, result); + } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index fe2390c..5bc40df 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -152,6 +152,11 @@ <update> Regenerate the EL parser using JavaCC 7.0.10. (markt) </update> + <fix> + Fix a bug that prevented the EL parser correctly parsing a literal Map + that used variables rather than literals for both keys and values. + (markt) + </fix> </changelog> </subsection> <subsection name="WebSocket"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org