Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.6.2, 1.7
    • Component/s: Engine
    • Labels:
      None

      Description

      When using #evaluate, all further macro processing is broken; old macros are not recognized anymore, and new macros cannot be defined.

      For example:

      #macro(aSimpleMacro)
        This is a simple macro
      #end
      ## called 3 times to show that it works each time
      #aSimpleMacro()
      #aSimpleMacro()
      #aSimpleMacro()
      
      #macro(doEval $b)
        #evaluate($x)
      
      #end
      
      #set($x = 'value of x')
      #doEval('$x')
      ## after the first call, which used an #evaluate, these two won't work anymore:
      #doEval('$x')
      #doEval('$x')
      
      #macro(anotherSimpleMacro)
        This is another simple macro
      #end
      ## This newly defined macro doesn't work, either...
      #anotherSimpleMacro()
      
      ## And the first macro, which worked well before, suddenly stops working
      #aSimpleMacro()
      {/noformat}
      
      should print:
      
      

      This is a simple macro
      This is a simple macro
      This is a simple macro

      value of x
      value of x
      value of x

      This is another simple macro

      This is a simple macro

      {/noformat}

      but instead prints:
      
      

      This is a simple macro
      This is a simple macro
      This is a simple macro

      value of x
      #doEval('$x')
      #doEval('$x')

      #anotherSimpleMacro()

      #aSimpleMacro(){/noformat}

        Activity

        Hide
        Nathan Bubna added a comment -

        Inline macro namespace was being dumped during parsing of the source to be evaluated.

        Show
        Nathan Bubna added a comment - Inline macro namespace was being dumped during parsing of the source to be evaluated.
        Hide
        Nathan Bubna added a comment -

        There is something funky here. If i do:

        String template = "#macro( eval $e )#evaluate($e)#end" +
        "\n#eval('foo')" +
        "\n#eval('bar')";
        String expected = "\nfoo"+
        "\nbar";
        assertEvalEquals(expected, template);

        Then i get

        foobar
        foo

        as the output. But, if i drop those newlines from the template and expectation:

        String template = "#macro( eval $e )#evaluate($e)#end" +
        "#eval('foo')" +
        "#eval('bar')";
        String expected = "foo"+
        "bar";
        assertEvalEquals(expected, template);

        then it works and i get just "foobar". This is with the trunk, of course. So, yeah, there's something screwy going on.

        Show
        Nathan Bubna added a comment - There is something funky here. If i do: String template = "#macro( eval $e )#evaluate($e)#end" + "\n#eval('foo')" + "\n#eval('bar')"; String expected = "\nfoo"+ "\nbar"; assertEvalEquals(expected, template); Then i get foobar foo as the output. But, if i drop those newlines from the template and expectation: String template = "#macro( eval $e )#evaluate($e)#end" + "#eval('foo')" + "#eval('bar')"; String expected = "foo"+ "bar"; assertEvalEquals(expected, template); then it works and i get just "foobar". This is with the trunk, of course. So, yeah, there's something screwy going on.
        Hide
        Byron Foster added a comment -

        I've checked in a test case for this issue, offending line commented out. Looks like RuntimeConstants.VM_PERM_INLINE_LOCAL needs to be true for this to fail.

        Show
        Byron Foster added a comment - I've checked in a test case for this issue, offending line commented out. Looks like RuntimeConstants.VM_PERM_INLINE_LOCAL needs to be true for this to fail.
        Hide
        Jarkko Viinamäki added a comment -

        Hmm. This works for me. What kind of JUnit TestCase did you use Byron?

        Show
        Jarkko Viinamäki added a comment - Hmm. This works for me. What kind of JUnit TestCase did you use Byron?
        Hide
        Byron Foster added a comment - - edited

        This is confirmed: the following simpler VTL (strict mode):

        #macro(eval $e)#evaluate($e)#end
        #eval("foo1")
        #eval("foo2")

        Results in:

        Threw: class org.apache.velocity.exception.ParseErrorException
        Msg: Macro '#eval' is not defined at /foo.vm[line 3, column 1]
        org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:319)
        org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:215)
        org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
        org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
        org.apache.velocity.Template.merge(Template.java:340)
        org.apache.velocity.Template.merge(Template.java:248)
        org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:343)

        Show
        Byron Foster added a comment - - edited This is confirmed: the following simpler VTL (strict mode): #macro(eval $e)#evaluate($e)#end #eval("foo1") #eval("foo2") Results in: Threw: class org.apache.velocity.exception.ParseErrorException Msg: Macro '#eval' is not defined at /foo.vm [line 3, column 1] org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:319) org.apache.velocity.runtime.directive.RuntimeMacro.render(RuntimeMacro.java:215) org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207) org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342) org.apache.velocity.Template.merge(Template.java:340) org.apache.velocity.Template.merge(Template.java:248) org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:343)

          People

          • Assignee:
            Unassigned
            Reporter:
            Sergiu Dumitriu
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development