Author: byron
Date: Wed Feb 11 05:31:45 2009
New Revision: 743234

URL: http://svn.apache.org/viewvc?rev=743234&view=rev
Log:
VELOCITY-688 Return to the original behavior of this issue

Modified:
    
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
    velocity/engine/trunk/src/test/org/apache/velocity/test/IndexTestCase.java
    
velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java?rev=743234&r1=743233&r2=743234&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
 (original)
+++ 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
 Wed Feb 11 05:31:45 2009
@@ -424,8 +424,10 @@
         {          
             if (strictRef)
             {
-                if (referenceType == QUIET_REFERENCE)
+                if (referenceType != QUIET_REFERENCE)
                 {
+                  log.error("Prepend the reference with '$!' e.g., $!" + 
literal().substring(1)
+                      + " if you want Velocity to ignore the reference when it 
evaluates to null");
                   if (value == null)
                   {
                     throw new VelocityException("Reference " + literal() 

Modified: 
velocity/engine/trunk/src/test/org/apache/velocity/test/IndexTestCase.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/IndexTestCase.java?rev=743234&r1=743233&r2=743234&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/IndexTestCase.java 
(original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/IndexTestCase.java 
Wed Feb 11 05:31:45 2009
@@ -29,6 +29,7 @@
     public IndexTestCase(String name)
     {
         super(name);
+        //DEBUG = true;
     }
 
     public void setUp() throws Exception
@@ -91,7 +92,7 @@
         assertEvalEquals("GOT NULL", "#set($i=$NULL)$boo[$i]");
         
         assertEvalEquals("321", "$a[-1]$a[ -2]$a[-3 ]");
-        assertEvalEquals("67xx", "#set($hash={1:11, 5:67, 
23:2})$hash[5]$hash[6]#if(!$hash[1000])xx#end");
+        assertEvalEquals("67xx", "#set($hash={1:11, 5:67, 
23:2})$hash[5]$!hash[6]#if(!$hash[1000])xx#end");
         
         // Some cases that should be evaluated as text
         assertEvalEquals("[]", "[]");

Modified: 
velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java?rev=743234&r1=743233&r2=743234&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java
 (original)
+++ 
velocity/engine/trunk/src/test/org/apache/velocity/test/StrictReferenceTestCase.java
 Wed Feb 11 05:31:45 2009
@@ -76,7 +76,7 @@
     public void testAllowNullValues()
         throws Exception
     {
-        evaluate("$bar");
+        evaluate("$!bar");
         assertEvalEquals("true", "#if($bar == $NULL)true#end");
         assertEvalEquals("true", "#set($foobar = $NULL)#if($foobar == 
$NULL)true#end");
         assertEvalEquals("13", "#set($list = [1, $NULL, 3])#foreach($item in 
$list)#if($item != $NULL)$item#end#end");
@@ -119,7 +119,7 @@
 
         // Mainly want to make sure no exceptions are thrown here
         assertEvalEquals("propiness", "$fargo.prop");
-        assertEvalEquals("", "$fargo.nullVal");
+        assertEvalEquals("", "$!fargo.nullVal");
         assertEvalEquals("propiness", "$fargo.next.prop");
 
         assertMethodEx("$fargo.foobar");
@@ -152,8 +152,8 @@
         assertVelocityEx("#set($fargo.prop = $NULL)$fargo.prop.next");
 
         // make sure no exceptions are thrown here
-        evaluate("$fargo.next.next");
-        evaluate("$fargo.next.nullVal");
+        evaluate("$!fargo.next.next");
+        evaluate("$!fargo.next.nullVal");
         evaluate("#foreach($item in $fargo.nullVal)#end");
     }
 
@@ -181,14 +181,14 @@
         fargo.next = new Fargo();
         context.put("fargo", fargo);      
       
-        assertVelocityEx("#set($foo = $NULL)$!foo");
-        assertEvalEquals("", "#set($foo = $NULL)$foo");
-        assertVelocityEx("$!fargo.nullVal");
-        assertEvalEquals("", "$fargo.nullVal");
-        assertVelocityEx("$!fargo.next.next");
-        assertEvalEquals("", "$fargo.next.next");
-        assertVelocityEx("$!fargo.next.nullVal");
-        assertEvalEquals("", "$fargo.next.nullVal");
+        assertVelocityEx("#set($foo = $NULL)$foo");
+        assertEvalEquals("", "#set($foo = $NULL)$!foo");
+        assertVelocityEx("$fargo.nullVal");
+        assertEvalEquals("", "$!fargo.nullVal");
+        assertVelocityEx("$fargo.next.next");
+        assertEvalEquals("", "$!fargo.next.next");
+        assertVelocityEx("$fargo.next.nullVal");
+        assertEvalEquals("", "$!fargo.next.nullVal");
     }
     
     /**


Reply via email to