Author: nbubna
Date: Thu Jan 22 07:39:02 2009
New Revision: 736677

URL: http://svn.apache.org/viewvc?rev=736677&view=rev
Log:
VELOCITY-675 fix NPE from #...@foo (thx to Jarkko Viinamaki)

Modified:
    velocity/engine/trunk/src/changes/changes.xml
    
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.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=736677&r1=736676&r2=736677&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Thu Jan 22 07:39:02 2009
@@ -27,6 +27,10 @@
   <body>
     <release version="1.7" date="In Subversion">
 
+      <action type="fix" dev="nbubna" issue="VELOCITY-675" due-to="Jarkko 
Viinamäki">
+        Fix NPE caused by #...@foo (w/o #end) in template.
+      </action>
+
       <action type="add" dev="byron" issue="VELOCITY-668" due-to="Jarkko 
Viinamäki">
        Minor performance tweaks based on Findbugs findings
       </action>

Modified: 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
URL: 
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java?rev=736677&r1=736676&r2=736677&view=diff
==============================================================================
--- 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
 (original)
+++ 
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
 Thu Jan 22 07:39:02 2009
@@ -127,25 +127,34 @@
             }
             else if( directiveName.startsWith("@") )
             {
-                // block macro call (normal macro call but has AST body)
-                directiveName = directiveName.substring(1);
+                if( this.jjtGetNumChildren() > 0 )
+                {
+                    // block macro call (normal macro call but has AST body)
+                    directiveName = directiveName.substring(1);
 
-                directive = new BlockMacro(directiveName);
-                directive.setLocation(getLine(), getColumn(), 
getTemplateName());
+                    directive = new BlockMacro(directiveName);
+                    directive.setLocation(getLine(), getColumn(), 
getTemplateName());
 
-                try
-                {
-                    directive.init( rsvc, context, this );
-                }
-                catch (TemplateInitException die)
-                {
-                    throw new TemplateInitException(die.getMessage(),
+                    try
+                    {
+                        directive.init( rsvc, context, this );
+                    }
+                    catch (TemplateInitException die)
+                    {
+                        throw new TemplateInitException(die.getMessage(),
                             (ParseException) die.getWrappedThrowable(),
                             die.getTemplateName(),
                             die.getColumnNumber() + getColumn(),
                             die.getLineNumber() + getLine());
+                    }
+                    isDirective = true;
+                }
+                else
+                {
+                    // this is a fake block macro call without a body. e.g. 
#...@foo
+                    // just render as it is
+                    isDirective = false;
                 }
-                isDirective = true;
             }
             else
             {

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=736677&r1=736676&r2=736677&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 
Thu Jan 22 07:39:02 2009
@@ -92,4 +92,9 @@
         assertEvalEquals(result, template);
     }
 
+    public void testVelocity675() throws Exception
+    {
+        assertEvalEquals("#...@foo", "#...@foo"); 
+    }
+
 }


Reply via email to