You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2020/05/28 20:11:08 UTC

[commons-jexl] branch master updated (9c865cd -> c8fd05a)

This is an automated email from the ASF dual-hosted git repository.

henrib pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git.


    from 9c865cd  Merge branch 'master' into JEXL-249
     new f62455e  JEXL-275: edge case of assignment from undefined var in safe mode was/is ok Task #JEXL-275 - Allow safe navigation as option
     new c17bd49  JEXL-249: java 1.8 is now the minimal version Task #JEXL-249 - Java 1.8 as minimum supported version
     new 07bdc85  JEXL-249: nitpicks for findbugs Task #JEXL-249 - Java 1.8 as minimum supported version
     new c8fd05a  JEXL-331: document unicode escape sequence Task #JEXL-331 - Please document \uXXXX escape sequence

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 RELEASE-NOTES.txt                                  |  2 ++
 .../org/apache/commons/jexl3/JexlArithmetic.java   |  3 +-
 .../commons/jexl3/internal/InterpreterBase.java    |  9 +++---
 .../commons/jexl3/internal/TemplateEngine.java     |  1 -
 .../jexl3/internal/TemplateInterpreter.java        |  1 -
 src/site/xdoc/changes.xml                          |  6 ++++
 src/site/xdoc/reference/syntax.xml                 | 13 +++++++--
 .../org/apache/commons/jexl3/AnnotationTest.java   |  2 ++
 .../org/apache/commons/jexl3/Issues200Test.java    | 34 +++++++++++++++++++++-
 9 files changed, 61 insertions(+), 10 deletions(-)


[commons-jexl] 02/04: JEXL-249: java 1.8 is now the minimal version Task #JEXL-249 - Java 1.8 as minimum supported version

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit c17bd49ff2573ebad440725eee0ca63253931d1d
Author: henrib <he...@apache.org>
AuthorDate: Thu May 28 17:09:12 2020 +0200

    JEXL-249: java 1.8 is now the minimal version
    Task #JEXL-249 - Java 1.8 as minimum supported version
---
 RELEASE-NOTES.txt         | 1 +
 src/site/xdoc/changes.xml | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 2428a98..5523532 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -61,6 +61,7 @@ New Features in 3.2:
 * JEXL-253:      Permissions by super type in JexlSandbox
 * JEXL-252:      Allow for interpolated strings to be used in property access operators
 * JEXL-250:      Safe navigation operator (?.)
+* JEXL-249:      Java 1.8 as minimum supported version
 * JEXL-248:      Allow range subexpression as an array property assignment identifier
 * JEXL-243:      Allow restricting available features in Script/Expressions
 * JEXL-238:      Restrict getLiteralClass to a Number for NumberLiterals
diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml
index b09d175..784312d 100644
--- a/src/site/xdoc/changes.xml
+++ b/src/site/xdoc/changes.xml
@@ -191,6 +191,9 @@
             <action dev="henrib" type="add" issue="JEXL-250" due-to="Dmitri Blinov">
                 Safe navigation operator
             </action>
+            <action dev="henrib" type="add" issue="JEXL-249" due-to="Dmitri Blinov">
+                Java 1.8 as minimum supported version
+            </action>
             <action dev="henrib" type="add" issue="JEXL-248" due-to="Dmitri Blinov">
                 Allow range subexpression as an array property assignment identifier
             </action>


[commons-jexl] 03/04: JEXL-249: nitpicks for findbugs Task #JEXL-249 - Java 1.8 as minimum supported version

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit 07bdc85a1420665a8123aafc6767e2b5054ae795
Author: henrib <he...@apache.org>
AuthorDate: Thu May 28 22:09:27 2020 +0200

    JEXL-249: nitpicks for findbugs
    Task #JEXL-249 - Java 1.8 as minimum supported version
---
 src/main/java/org/apache/commons/jexl3/JexlArithmetic.java             | 3 ++-
 src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java    | 1 -
 .../java/org/apache/commons/jexl3/internal/TemplateInterpreter.java    | 1 -
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
index 61335f9..5b1c4a2 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
@@ -21,6 +21,7 @@ import org.apache.commons.jexl3.introspection.JexlMethod;
 
 import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.math.MathContext;
@@ -210,7 +211,7 @@ public class JexlArithmetic {
         if (ctor != null) {
             try {
                 return ctor.newInstance(astrict, bigdContext, bigdScale);
-            } catch (Exception xany) {
+            } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException xany) {
                 // it was worth the try
             }
         }
diff --git a/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java b/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
index b838b08..e8607cf 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
@@ -655,7 +655,6 @@ public final class TemplateEngine extends JxltEngine {
 
         @Override
         protected Object evaluate(Interpreter interpreter) {
-            final int size = exprs.length;
             Object value;
             // common case: evaluate all expressions & concatenate them as a string
             StringBuilder strb = new StringBuilder();
diff --git a/src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java b/src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java
index c208927..ebfab0d 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java
@@ -159,7 +159,6 @@ public class TemplateInterpreter extends Interpreter {
      */
     private void printComposite(TemplateEngine.CompositeExpression composite) {
         TemplateEngine.TemplateExpression[] cexprs = composite.exprs;
-        final int size = cexprs.length;
         Object value;
         for (TemplateExpression cexpr : cexprs) {
             value = cexpr.evaluate(this);


[commons-jexl] 04/04: JEXL-331: document unicode escape sequence Task #JEXL-331 - Please document \uXXXX escape sequence

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit c8fd05a5448581f6388aef27e2866da1b0c4438e
Author: henrib <he...@apache.org>
AuthorDate: Thu May 28 22:10:37 2020 +0200

    JEXL-331: document unicode escape sequence
    Task #JEXL-331 - Please document \uXXXX escape sequence
---
 RELEASE-NOTES.txt                  |  1 +
 src/site/xdoc/changes.xml          |  3 +++
 src/site/xdoc/reference/syntax.xml | 13 +++++++++++--
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 5523532..6d1bca8 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -75,6 +75,7 @@ New Features in 3.2:
 
 Bugs Fixed in 3.2:
 ==================
+* JEXL-331:      Please document \uXXXX escape sequence
 * JEXL-330:      JexlException.Parsing.getMessage() throws exception when parse error is in long expression
 * JEXL-328:      JXLT template scripts evaluation do not process pragmas
 * JEXL-327:      map[null] does not work in assignment context
diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml
index 784312d..fbf12b5 100644
--- a/src/site/xdoc/changes.xml
+++ b/src/site/xdoc/changes.xml
@@ -26,6 +26,9 @@
     </properties>
     <body>
         <release version="3.2" date="unreleased">
+            <action dev="henrib" type="fix" issue="JEXL-331" due-to="David Costanzo">
+                Please document \uXXXX escape sequence
+            </action>
             <action dev="henrib" type="fix" issue="JEXL-330" due-to="David Costanzo">
                 JexlException.Parsing.getMessage() throws exception when parse error is in long expression
             </action>
diff --git a/src/site/xdoc/reference/syntax.xml b/src/site/xdoc/reference/syntax.xml
index 36e784b..720c5a5 100644
--- a/src/site/xdoc/reference/syntax.xml
+++ b/src/site/xdoc/reference/syntax.xml
@@ -346,14 +346,23 @@
                         Can start and end with either <code>'</code> or <code>"</code> delimiters, e.g.
                         <code>"Hello world"</code> and
                         <code>'Hello world'</code> are equivalent.
-                        <p>The escape character is <code>\</code> (backslash); it only escapes the string delimiter</p>
+                        <p>The escape character is <code>\</code> (backslash).
+                        Unicode characters can be used in string literals;
+                            <lu>Unicode escape sequences consist of:
+                                <li> a backslash '\' </li>
+                                <li>a 'u' </li>
+                                <li>4 hexadecimal digits ([0-9],[A-H],[a-h]).</li>
+                            </lu>
+                            Such sequences represent the UTF-16 encoding of a Unicode character,
+                            for example, <code>'a'</code> is equivalent to <code>'\u0061'</code>.
+                        </p>
                     </td>
                 </tr>
                 <tr>
                     <td>Multiline format literals</td>
                     <td>
                         Start and end with <code>`</code> delimiter - back-quote -, e.g. <code>`Hello world`</code>
-                        <p>The escape character is <code>\</code> (backslash); it only escapes the string delimiter.</p>
+                        <p>The escape character is <code>\</code> (backslash); Unicode escape sequences can also be used.</p>
                         These format literals can span multiple lines and allow Unified JEXL expressions (JSTL like expressions)
                         to be interpolated. If a variable <code>user</code> valued <code>JEXL</code>is present in the environment - whether
                         as a local or global variable -, the format <code>`Hello ${user}`</code> will evaluate as <code>Hello JEXL</code>.


[commons-jexl] 01/04: JEXL-275: edge case of assignment from undefined var in safe mode was/is ok Task #JEXL-275 - Allow safe navigation as option

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit f62455eba65a067b54aef36434122aa5d67892c0
Author: henrib <he...@apache.org>
AuthorDate: Thu May 28 17:06:45 2020 +0200

    JEXL-275: edge case of assignment from undefined var in safe mode was/is ok
    Task #JEXL-275 - Allow safe navigation as option
---
 .../commons/jexl3/internal/InterpreterBase.java    |  9 +++---
 .../org/apache/commons/jexl3/AnnotationTest.java   |  2 ++
 .../org/apache/commons/jexl3/Issues200Test.java    | 34 +++++++++++++++++++++-
 3 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
index 35ca21e..cee0905 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
@@ -33,6 +33,7 @@ import org.apache.commons.jexl3.introspection.JexlPropertyGet;
 import org.apache.commons.jexl3.introspection.JexlPropertySet;
 import org.apache.commons.jexl3.introspection.JexlUberspect;
 import org.apache.commons.jexl3.parser.ASTArrayAccess;
+import org.apache.commons.jexl3.parser.ASTAssignment;
 import org.apache.commons.jexl3.parser.ASTFunctionNode;
 import org.apache.commons.jexl3.parser.ASTIdentifier;
 import org.apache.commons.jexl3.parser.ASTIdentifierAccess;
@@ -289,10 +290,10 @@ public abstract class InterpreterBase extends ParserVisitor {
         }
         String name = identifier.getName();
         Object value = context.get(name);
-        if (value == null
-            && !(identifier.jjtGetParent() instanceof ASTReference)
-            && !(context.has(name))) {
-                return unsolvableVariable(identifier, name, true); // undefined
+        if (value == null && !context.has(name)
+            && !(identifier.jjtGetParent() instanceof ASTAssignment && isSafe())
+            && !(identifier.jjtGetParent() instanceof ASTReference)) {
+            return unsolvableVariable(identifier, name, true); // undefined
         }
         return value;
     }
diff --git a/src/test/java/org/apache/commons/jexl3/AnnotationTest.java b/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
index 9ac3572..b299179 100644
--- a/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
+++ b/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
@@ -136,6 +136,7 @@ public class AnnotationTest extends JexlTestCase {
 
         r = null;
         // will make an error and throw
+        options.setSafe(false);
         try {
             r = e.execute(jc, true, false);
             Assert.fail("should have thrown");
@@ -151,6 +152,7 @@ public class AnnotationTest extends JexlTestCase {
         } catch (JexlException.Variable xjexl) {
             Assert.fail("should not have thrown");
         }
+        options.setSafe(true);
 
         r = null;
         // will not make an error and will not throw
diff --git a/src/test/java/org/apache/commons/jexl3/Issues200Test.java b/src/test/java/org/apache/commons/jexl3/Issues200Test.java
index 6d66ec9..3045efd 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues200Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues200Test.java
@@ -617,7 +617,39 @@ public class Issues200Test extends JexlTestCase {
             Assert.assertEquals("xyz", xvar.getVariable());
         }
     }
-    
+
+    @Test
+    public void test275b() throws Exception {
+        JexlContext ctxt = new MapContext();
+        //ctxt.set("out", System.out);
+        JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
+        JexlScript e = jexl.createScript("var xyz = xyz");
+        try {
+            Object o = e.execute(ctxt);
+            Assert.assertNull(o);
+        } catch (JexlException.Variable xvar) {
+            Assert.fail("should not have thrown");
+            // Assert.assertEquals("xyz", xvar.getVariable());
+        }
+    }
+
+    @Test
+    public void test275c() throws Exception {
+        JexlContext ctxt = new MapContext();
+        //ctxt.set("out", System.out);
+        JexlEngine jexl = new JexlBuilder().strict(true).safe(true).silent(true).create();
+        JexlScript e;
+        Object r;
+        e = jexl.createScript("(s, v)->{  var x = y ; 42; }");
+        // wont make an error
+        try {
+            r = e.execute(ctxt, false, true);
+            Assert.assertEquals(42, r);
+        } catch (JexlException.Variable xjexl) {
+            Assert.fail("should not have thrown");
+        }
+    }
+
     @Test
     public void test278() throws Exception {
         String[] srcs = new String[]{