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/04/29 10:26:57 UTC

[commons-jexl] branch master updated: JEXL-275: strict mode is enough (wrt safe) to detect undefined vars as arguments Task #JEXL-275 - Allow safe navigation as option

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


The following commit(s) were added to refs/heads/master by this push:
     new c716d1d  JEXL-275: strict mode is enough (wrt safe) to detect undefined vars as arguments Task #JEXL-275 - Allow safe navigation as option
c716d1d is described below

commit c716d1de3fe1bde6a330629939c45745e9e65e95
Author: henrib <he...@apache.org>
AuthorDate: Wed Apr 29 12:25:00 2020 +0200

    JEXL-275: strict mode is enough (wrt safe) to detect undefined vars as arguments
    Task #JEXL-275 - Allow safe navigation as option
---
 .../commons/jexl3/internal/InterpreterBase.java       |  4 +---
 .../java/org/apache/commons/jexl3/Issues200Test.java  | 19 +++++++++++++++++--
 2 files changed, 18 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 8655760..35ca21e 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
@@ -292,9 +292,7 @@ public abstract class InterpreterBase extends ParserVisitor {
         if (value == null
             && !(identifier.jjtGetParent() instanceof ASTReference)
             && !(context.has(name))) {
-                return isSafe()
-                    ? null
-                    : unsolvableVariable(identifier, name, true); // undefined
+                return unsolvableVariable(identifier, name, true); // undefined
         }
         return value;
     }
diff --git a/src/test/java/org/apache/commons/jexl3/Issues200Test.java b/src/test/java/org/apache/commons/jexl3/Issues200Test.java
index 80114e4..01918f9 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues200Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues200Test.java
@@ -603,7 +603,22 @@ public class Issues200Test extends JexlTestCase {
             Assert.assertTrue(sxs.contains("jvm"));
         }
     }
+    
+    @Test
+    public void test275a() throws Exception {
+        JexlContext ctxt = new MapContext();
+        ctxt.set("out", System.out);
+        JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
 
+        JexlScript e = jexl.createScript("out.println(xyz)");
+        try {
+            Object o = e.execute(ctxt);
+            Assert.fail("should have thrown");
+        } catch (JexlException.Variable xvar) {
+            Assert.assertEquals("xyz", xvar.getVariable());
+        }
+    }
+    
     @Test
     public void test278() throws Exception {
         String[] srcs = new String[]{
@@ -846,14 +861,14 @@ public class Issues200Test extends JexlTestCase {
         Assert.assertEquals(2, result);
         result = script.execute(ctxt, 2);
         Assert.assertEquals(3, result);
-        options.setSafe(false);
+        options.setStrict(true);
         try {
             result = script.execute(ctxt, 0);
             Assert.fail("should have failed!");
         } catch (JexlException.Variable xvar) {
             Assert.assertTrue(xvar.getMessage().contains("y"));
         }
-        options.setSafe(true);
+        options.setStrict(false);
         try {
             result = script.execute(ctxt, 0);
         } catch (JexlException xvar) {