Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-944

Macros in string literals are not resolved when local_scope is enabled

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • 2.0, 2.1, 2.2, 2.3
    • None
    • Engine
    • None

    Description

      When local scope is enabled with 

      velocimacro.inline.local_scope=true
      

      a template that is using a macro in string literal is not working correctly.

      Example template:

      #macro( m $v )
      <span>$v</span>
      #end
      #set($v = "#m('bar')")
      $v
      #m( 'foo' )
      

      Actual result:

      #m('bar')
      <span>foo</span>
      

      Expected result:

      <span>bar</span>
      <span>foo</span>
      

      The example template is working correctly for velocity 1.7.

      After debugging a bit I think the problem might be caused by creating a new Template instance in org.apache.velocity.runtime.parser.node.ASTStringLiteral#init. Because of that, when macro is being resolved, there is no macro instance available in local scope (template instance) and it is rendered as string. Locally I was able to make it work by using this.template when context.getCurrentResource() returns null.

      Attachments

        Activity

          People

            Unassigned Unassigned
            Jakub Isakow Jakub Isakow
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: