commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1166773 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl2/Interpreter.java main/java/org/apache/commons/jexl2/JexlArithmetic.java test/java/org/apache/commons/jexl2/IfTest.java
Date Thu, 08 Sep 2011 16:00:32 GMT
Author: henrib
Date: Thu Sep  8 16:00:32 2011
New Revision: 1166773

URL: http://svn.apache.org/viewvc?rev=1166773&view=rev
Log:
Fixed issue due to elvis operator not coercing the condition to boolean using the JexlArithmetic
instance

Modified:
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
    commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java?rev=1166773&r1=1166772&r2=1166773&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java Thu
Sep  8 16:00:32 2011
@@ -1348,7 +1348,7 @@ public class Interpreter implements Pars
                 return node.jjtGetChild(2).jjtAccept(this, data);
             }
         }
-        if (condition != null && !Boolean.FALSE.equals(condition)) {
+        if (condition != null && arithmetic.toBoolean(condition)) {
             return condition;
         } else {
             return node.jjtGetChild(1).jjtAccept(this, data);

Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java?rev=1166773&r1=1166772&r2=1166773&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java Thu
Sep  8 16:00:32 2011
@@ -744,7 +744,8 @@ public class JexlArithmetic {
             double number = toDouble(val);
             return !Double.isNaN(number) && number != 0.d;
         } else if (val instanceof String) {
-            return Boolean.valueOf((String) val).booleanValue();
+            String strval = val.toString();
+            return strval.length() > 0 && !"false".equals(strval);
         }
         // TODO: is this a reasonable default?
         return false;

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java?rev=1166773&r1=1166772&r2=1166773&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java Thu Sep 
8 16:00:32 2011
@@ -251,6 +251,62 @@ public class IfTest extends JexlTestCase
             o = jc.get("x.y.z");
             assertEquals("Should be quux", "quux", o);
         }
+        
+        jc.set("foo", Double.NaN);
+
+        for (int l = 0; l < 4; ++l) {
+            jexl.setLenient((l & 1) != 0);
+            jexl.setSilent((l & 2) != 0);
+            o = e.evaluate(jc);
+            assertEquals("Should be quux", "quux", o);
+            o = jc.get("x.y.z");
+            assertEquals("Should be quux", "quux", o);
+        }
+                
+        jc.set("foo", "");
+
+        for (int l = 0; l < 4; ++l) {
+            jexl.setLenient((l & 1) != 0);
+            jexl.setSilent((l & 2) != 0);
+            o = e.evaluate(jc);
+            assertEquals("Should be quux", "quux", o);
+            o = jc.get("x.y.z");
+            assertEquals("Should be quux", "quux", o);
+        }
+                        
+        jc.set("foo", "false");
+
+        for (int l = 0; l < 4; ++l) {
+            jexl.setLenient((l & 1) != 0);
+            jexl.setSilent((l & 2) != 0);
+            o = e.evaluate(jc);
+            assertEquals("Should be quux", "quux", o);
+            o = jc.get("x.y.z");
+            assertEquals("Should be quux", "quux", o);
+        }               
+        
+        jc.set("foo", 0d);
+
+        for (int l = 0; l < 4; ++l) {
+            jexl.setLenient((l & 1) != 0);
+            jexl.setSilent((l & 2) != 0);
+            o = e.evaluate(jc);
+            assertEquals("Should be quux", "quux", o);
+            o = jc.get("x.y.z");
+            assertEquals("Should be quux", "quux", o);
+        }
+                
+        jc.set("foo", 0);
+
+        for (int l = 0; l < 4; ++l) {
+            jexl.setLenient((l & 1) != 0);
+            jexl.setSilent((l & 2) != 0);
+            o = e.evaluate(jc);
+            assertEquals("Should be quux", "quux", o);
+            o = jc.get("x.y.z");
+            assertEquals("Should be quux", "quux", o);
+        }
+
 
         jc.set("foo", "bar");
 
@@ -265,4 +321,5 @@ public class IfTest extends JexlTestCase
 
         debuggerCheck(jexl);
     }
+
 }



Mime
View raw message