velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Boris Partensky <boris.parten...@gmail.com>
Subject upgrading from 1.5 to 1.7 compatibility issues
Date Mon, 30 Apr 2012 15:49:39 GMT
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);

    }

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message