From ead820a5a3d788f164602396c9d1e0415b71940e Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Sat, 28 Dec 2019 12:17:30 +0000 Subject: [engine] Fix VELOCITY-904 again git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1872050 13f79535-47bb-0310-9956-ffa450edef68 --- .../runtime/directive/VelocimacroProxy.java | 23 ++++++++++++++++++---- .../runtime/parser/node/ASTStringLiteral.java | 10 +++++----- 2 files changed, 24 insertions(+), 9 deletions(-) (limited to 'velocity-engine-core/src/main/java/org/apache/velocity/runtime') 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 9fca114c..ea950f1f 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,6 +26,10 @@ 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; import org.apache.velocity.runtime.parser.node.SimpleNode; import org.apache.velocity.util.StringUtils; @@ -266,10 +270,13 @@ public class VelocimacroProxy extends Directive { /* allow for nested calls */ Deque literalsStack = (Deque)context.get(literalArgArray[i]); - literalsStack.removeFirst(); - if (literalsStack.size() == 0) + if (literalsStack != null) /* may be null if argument was missing in macro call */ { - context.remove(literalArgArray[i]); + literalsStack.removeFirst(); + if (literalsStack.size() == 0) + { + context.remove(literalArgArray[i]); + } } } } @@ -410,7 +417,15 @@ public class VelocimacroProxy extends Directive literalsStack = new LinkedList(); context.put(literalArgArray[i], literalsStack); } - literalsStack.addFirst(argNode.literal()); + /* Reflects the strange 1.7 behavor... */ + if (argNode instanceof ASTReference || argNode instanceof ASTStringLiteral || argNode instanceof ASTObjectArray || argNode instanceof ASTMap) + { + literalsStack.addFirst(argNode.literal()); + } + else + { + literalsStack.addFirst('$' + macroArg.name); + } } } diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java index 460a7b76..ff7a98c9 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java @@ -104,6 +104,11 @@ public class ASTStringLiteral extends SimpleNode */ String img = getFirstToken().image; + /* + the literal string *should* contain enclosing quotes + */ + literal = img; + image = img.substring(1, img.length() - 1); if (img.startsWith("\"")) @@ -166,11 +171,6 @@ public class ASTStringLiteral extends SimpleNode return data; } - public String literal() - { - return image; - } - /** * Adjust all the line and column numbers that comprise a node so that they * are corrected for the string literals position within the template file. -- cgit v1.2.3