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

Macros in string literals are not resolved when local_scope is enabled

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: 2.0, 2.1, 2.2, 2.3
    • Fix Version/s: None
    • Component/s: Engine
    • Labels:
      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

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

              Dates

              • Created:
                Updated: