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

"Jakub Isakow (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:comment-tabpanel&focusedCommentId=17886653#comment-17886653 ] 

Jakub Isakow commented on VELOCITY-944:
---------------------------------------

I've attached pom.xml and a test file. The 
{code}
mvn clean test
{code}
ends with
{noformat}
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running VelocityTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.282 sec <<< FAILURE!
name(VelocityTest)  Time elapsed: 0.216 sec  <<< FAILURE!
org.junit.ComparisonFailure:
Expecting actual:
  "<span>foo</span>
some text #m( 'bar' )"
to be equal to:
  "<span>foo</span>
some text <span>bar</span>"
...
{noformat}

> 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
>         Attachments: VelocityTest.java, pom.xml
>
>
> 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.