This is an automated email from the ASF dual-hosted git repository.

cbrisson pushed a commit to branch bugfix/velocity-940
in repository https://gitbox.apache.org/repos/asf/velocity-engine.git

commit a643483629ebe2659f732a388deb859042cf8125
Author: Claude Brisson <[email protected]>
AuthorDate: Sun Mar 26 14:09:35 2023 +0200

    Fix specific recursion bug (non-block call inside block call)
---
 .../runtime/directive/VelocimacroProxy.java        |  3 +--
 .../velocity/test/issues/Velocity940TestCase.java  | 24 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git 
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
 
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
index d3b8ff5c..0aa62ddc 100644
--- 
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
+++ 
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
@@ -197,10 +197,9 @@ public class VelocimacroProxy extends Directive
         int callArgNum = node.jjtGetNumChildren();
 
         // if this macro was invoked by a call directive, we might have a body 
AST here.
-        Object oldBodyRef = null;
+        Object oldBodyRef = context.remove(bodyReference);
         if (body != null)
         {
-            oldBodyRef = context.get(bodyReference);
             context.put(bodyReference, body);
             callArgNum--;  // Remove the body AST from the arg count
         }
diff --git 
a/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity940TestCase.java
 
b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity940TestCase.java
new file mode 100644
index 00000000..45a318a0
--- /dev/null
+++ 
b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity940TestCase.java
@@ -0,0 +1,24 @@
+package org.apache.velocity.test.issues;
+
+import org.apache.velocity.test.BaseTestCase;
+import org.junit.Test;
+
+public class Velocity940TestCase extends BaseTestCase
+{
+    public Velocity940TestCase(String name)
+    {
+        super(name);
+    }
+
+    @Test
+    public void testNonBlockInsideBlock()
+    {
+        assertEvalEquals("Something First Something Second ", "#macro(test 
$label)Something $!label 
$!bodyContent#{end}#@test('First')#test('Second')#end");
+    }
+
+    public void testBlockInsideBlock()
+    {
+        assertEvalEquals("Something First Something Second Somewhere", 
"#macro(test $label)Something $!label 
$!bodyContent#{end}#@test('First')#@test('Second')Somewhere#end#end");
+    }
+
+}

Reply via email to