[jira] [Closed] (VELOCITY-944) Macros in string literals are not resolved when local_scope is enabled

"Claude Brisson (Jira)" <[email protected]>
Newsgroups gmane.comp.jakarta.velocity.devel
Message-ID <[email protected]>
     [ https://issues.apache.org/jira/browse/VELOCITY-944?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claude Brisson closed VELOCITY-944.
-----------------------------------
      Assignee: Claude Brisson
    Resolution: Cannot Reproduce

I could not reproduce the problem in any of the 2.x versions. Please reopen with a complete test case.


> Macros in string literals are not resolved when local_scope is enabled
> ----------------------------------------------------------------------
>
>                 Key: VELOCITY-944
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-944
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 2.0, 2.1, 2.2, 2.3
>            Reporter: Jakub Isakow
>            Assignee: Claude Brisson
>            Priority: Critical
>
> When local scope is enabled with 
> {noformat}
> velocimacro.inline.local_scope=true
> {noformat}
> a template that is using a macro in string literal is not working correctly.
> Example template:
> {code}
> #macro( m $v )
> <span>$v</span>
> #end
> #set($v = "#m('bar')")
> $v
> #m( 'foo' )
> {code}
> Actual result:
> {code}
> #m('bar')
> <span>foo</span>
> {code}
> Expected result:
> {code}
> <span>bar</span>
> <span>foo</span>
> {code}
> 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|https://github.com/apache/velocity-engine/blob/2.3/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java#L145-L149]. 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}}. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)
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.