aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2020-01-23 16:51:09 +0000
committerClaude Brisson <cbrisson@apache.org>2020-01-23 16:51:09 +0000
commitbf33425e64cb59b0f69ef60296f5fde84dfd9558 (patch)
treef4476265ba10820be15613105b8339c7409d9593 /velocity-engine-core
parent8cec722a4a551fc3645796bc4e753f956438f3fb (diff)
downloadapache-velocity-engine-bf33425e64cb59b0f69ef60296f5fde84dfd9558.tar.gz
[engine] Fix VELOCITY-926
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1873069 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core')
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java11
-rwxr-xr-xvelocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity926TestCase.java39
2 files changed, 47 insertions, 3 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 c9956c71..e8467fcf 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
@@ -26,8 +26,6 @@ import org.apache.velocity.runtime.Renderable;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.directive.Macro.MacroArg;
-import org.apache.velocity.runtime.parser.node.ASTMap;
-import org.apache.velocity.runtime.parser.node.ASTObjectArray;
import org.apache.velocity.runtime.parser.node.ASTReference;
import org.apache.velocity.runtime.parser.node.ASTStringLiteral;
import org.apache.velocity.runtime.parser.node.Node;
@@ -402,7 +400,6 @@ public class VelocimacroProxy extends Directive
break;
}
- context.put(macroArg.name, newVal);
values[(i-1) * 2 + 1] = newVal;
/* when preserveArgumentsLiterals is true, we still store the actual reference passed to the macro
@@ -429,6 +426,14 @@ public class VelocimacroProxy extends Directive
}
}
+ // Now really put the values in the context
+ for (int i = 1; i < macroArgs.size(); i++)
+ {
+ MacroArg macroArg = macroArgs.get(i);
+ Object value = values[(i-1) * 2 + 1];
+ context.put(macroArg.name, value);
+ }
+
// return the array of replaced and new values
return values;
}
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity926TestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity926TestCase.java
new file mode 100755
index 00000000..1a335507
--- /dev/null
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity926TestCase.java
@@ -0,0 +1,39 @@
+package org.apache.velocity.test.issues;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.test.BaseTestCase;
+
+/**
+ * This class tests VELOCITY-926.
+ */
+public class Velocity926TestCase extends BaseTestCase
+{
+ public Velocity926TestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testNamesCollision()
+ {
+ assertEvalEquals("bar foo", "#set($foo='foo')#set($bar='bar')#macro(test, $foo, $bar)$foo $bar#end#test($bar, $foo)");
+ }
+}