upgrading from 1.5 to 1.7 compatibility issues

Boris Partensky <[email protected]>
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <CABsrNP9Q9wGptkgiaMwDSSch__DNA4wc9FmrJFGJA762XEZavQ@mail.gmail.com>
Hello, while going through the upgrade I noticed an incompatible
behavior during nested macro evaluation. Looks like in 1.7 (all
default properties) child macro has access to variables set in parent
macro scope (and those take precedence over globals), and 1.5 sees
globals. In the following example, in 1.5 unit test the following
template will evaluate to "globalvar", and in 1.7 - to
"outermacroparam". Is this expected behavior?


1.5 test case


public void testVelocityNestedMacroScope() throws Exception
    {
        VelocityEngine ve = new VelocityEngine();

        ve.init();

        String template = "#macro(outerMacro $arg1)"+
                          "#innerMacro('blah')"+
                          "#end"+
                          "#macro(innerMacro $arg2)$arg1#end"+

"#set($arg1='globalval')#outerMacro('outermacroparam')";
        StringWriter eval = new StringWriter();
        boolean b = ve.evaluate(new VelocityContext(), eval, "foo", template);
        assertEquals(eval.toString(), "globalval", eval.toString());

    }

1.7 test case


 public void testVelocityNestedMacroScope()
    {
        String template = "#macro(outerMacro $arg1)"+
                          "#innerMacro('blah')"+
                          "#end"+
                          "#macro(innerMacro $arg2)$arg1#end"+

"#set($arg1='globalvar')#outerMacro('outermacroparam')";
        String eval = evaluate(template);
        assertEquals(eval, "outermacroparam", eval);

    }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.