commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1751647 - in /commons/proper/jexl/trunk: RELEASE-NOTES.txt src/main/java/org/apache/commons/jexl3/parser/JexlParser.java src/site/xdoc/changes.xml src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
Date Wed, 06 Jul 2016 09:40:40 GMT
Author: henrib
Date: Wed Jul  6 09:40:39 2016
New Revision: 1751647

URL: http://svn.apache.org/viewvc?rev=1751647&view=rev
Log:
JEXL: 
Fixing JEXL-202 by extending parsing check on l-value for all assignment operators

Modified:
    commons/proper/jexl/trunk/RELEASE-NOTES.txt
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
    commons/proper/jexl/trunk/src/site/xdoc/changes.xml
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java

Modified: commons/proper/jexl/trunk/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/RELEASE-NOTES.txt?rev=1751647&r1=1751646&r2=1751647&view=diff
==============================================================================
--- commons/proper/jexl/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/jexl/trunk/RELEASE-NOTES.txt Wed Jul  6 09:40:39 2016
@@ -27,7 +27,7 @@ Version 3.0.1 is a micro release to fix
 
 Bugs Fixed in 3.0.1:
 ====================
-
+* JEXL-202:     Detect invalid assignment operator usage with non-assignable l-value during
script parsing
 * JEXL-198:     JxltEngine Template does not expose pragmas
 * JEXL-196:     Script execution hangs while calling method with one argument without parameter
 * JEXL-194      allow synchronization on iterableValue in foreach statement

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java?rev=1751647&r1=1751646&r2=1751647&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
Wed Jul  6 09:40:39 2016
@@ -25,6 +25,9 @@ import org.apache.commons.jexl3.internal
 
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.TreeMap;
 import java.util.Stack;
 
@@ -171,6 +174,22 @@ public abstract class JexlParser extends
     }
 
     /**
+     * The set of assignment operators as classes.
+     */
+    @SuppressWarnings("unchecked")
+    private static final Set<Class<? extends JexlNode>> ASSIGN_NODES = new HashSet<Class<?
extends JexlNode>>(
+        Arrays.asList(
+            ASTAssignment.class,
+            ASTSetAddNode.class,
+            ASTSetMultNode.class,
+            ASTSetDivNode.class,
+            ASTSetAndNode.class,
+            ASTSetOrNode.class,
+            ASTSetXorNode.class,
+            ASTSetSubNode.class
+        )
+    );
+    /**
      * Called by parser at end of node construction.
      * <p>Detects "Ambiguous statement" and 'non-leaft value assignment'.</p>
      * @param node the node
@@ -186,7 +205,7 @@ public abstract class JexlParser extends
             popFrame();
         } else if (node instanceof ASTAmbiguous) {
             throwParsingException(JexlException.Ambiguous.class, node);
-        } else if (node instanceof ASTAssignment) {
+        } else if (ASSIGN_NODES.contains(node.getClass())) {
             JexlNode lv = node.jjtGetChild(0);
             if (!lv.isLeftValue()) {
                 throwParsingException(JexlException.Assignment.class, lv);

Modified: commons/proper/jexl/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/site/xdoc/changes.xml?rev=1751647&r1=1751646&r2=1751647&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/jexl/trunk/src/site/xdoc/changes.xml Wed Jul  6 09:40:39 2016
@@ -26,6 +26,9 @@
     </properties>
     <body>
         <release version="3.0.1" date="unreleased">
+            <action dev="henrib" type="fix" issue="JEXL-202" due-to="Dmitri Blinov">
+                Detect invalid assignment operator usage with non-assignable l-value during
script parsing
+            </action>
             <action dev="henrib" type="fix" issue="JEXL-198" due-to="Terefang Verigorn">
                 JxltEngine Template does not expose pragmas
             </action>

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java?rev=1751647&r1=1751646&r2=1751647&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
(original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
Wed Jul  6 09:40:39 2016
@@ -48,12 +48,17 @@ public class ParserTest extends TestCase
     }
 
     public void testErrorAssign() throws Exception {
-        Parser parser = new Parser(new StringReader(";"));
-        try {
-            JexlNode sn = parser.parse(null, "foo() = 1;", null, false, false);
-            fail("should have failed on invalid assignment");
-        } catch (JexlException.Parsing xparse) {
-            // ok
+        String[] ops = { "=", "+=", "-=", "/=", "*=", "^=", "&=", "|=" };
+        for(String op : ops) {
+            Parser parser = new Parser(new StringReader(";"));
+            try {
+                JexlNode sn = parser.parse(null, "foo() "+op+" 1;", null, false, false);
+                fail("should have failed on invalid assignment " + op);
+            } catch (JexlException.Parsing xparse) {
+                // ok
+                String ss = xparse.getDetail();
+                String sss = xparse.toString();
+            }
         }
     }
 



Mime
View raw message