Author: nbubna
Date: Fri Jan 23 09:26:43 2009
New Revision: 737104

URL: http://svn.apache.org/viewvc?rev=737104&view=rev
Log:
VELOCITY-685 fix strict macro args with block macros (thx to Jarkko Viinamaki)

Modified:
    velocity/engine/trunk/src/changes/changes.xml
    
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
    
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
    
velocity/engine/trunk/src/test/org/apache/velocity/test/BlockMacroTestCase.java

Modified: velocity/engine/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/changes/changes.xml?rev=737104&r1=737103&r2=737104&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Fri Jan 23 09:26:43 2009
@@ -26,6 +26,10 @@
 
   <body>
     <release version="1.7" date="In Subversion">
+      
+      <action type="fix" dev="nbubna" issue="VELOCITY-685" due-to="Jarkko 
Viinamäki">
+        Make velocimacro.arguments.strict=true work with block macros.
+      </action>
 
       <action type="add" dev="byron" issue="VELOCITY-623">
        Added a property for changing escape behavior such that putting a 
forward

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java?rev=737104&r1=737103&r2=737104&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
 (original)
+++ 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
 Fri Jan 23 09:26:43 2009
@@ -276,7 +276,7 @@
             try
             {
                // mainly check the number of arguments
-                vmProxy.checkArgs(context, node);
+                vmProxy.checkArgs(context, node, body != null);
             }
             catch (TemplateInitException die)
             {

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?rev=737104&r1=737103&r2=737104&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
 (original)
+++ 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
 Fri Jan 23 09:26:43 2009
@@ -271,10 +271,14 @@
      * we are not, and strictArguments is active, then throw 
TemplateInitException.
      * This method is called during macro render, so it must be thread safe.
      */
-    public void checkArgs(InternalContextAdapter context, Node node)
+    public void checkArgs(InternalContextAdapter context, Node node, boolean 
hasBody)
     {
         // check how many arguments we have
         int i = node.jjtGetNumChildren();
+        
+        // if macro call has a body (BlockMacro) then don't count the body as 
an argument
+        if( hasBody )
+            i--;
 
         // Throw exception for invalid number of arguments?
         if (getNumArgs() != i)

Modified: 
velocity/engine/trunk/src/test/org/apache/velocity/test/BlockMacroTestCase.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/BlockMacroTestCase.java?rev=737104&r1=737103&r2=737104&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/test/org/apache/velocity/test/BlockMacroTestCase.java 
(original)
+++ 
velocity/engine/trunk/src/test/org/apache/velocity/test/BlockMacroTestCase.java 
Fri Jan 23 09:26:43 2009
@@ -96,5 +96,11 @@
     {
         assertEvalEquals("#...@foo", "#...@foo"); 
     }
-
+    
+    public void testVelocity685() throws Exception
+    {
+        engine.setProperty(RuntimeConstants.VM_ARGUMENTS_STRICT, Boolean.TRUE);
+        assertEvalEquals(" ", "#macro(foo)#end #...@foo() junk #end");
+    }
 }
+


Reply via email to