#111 Eval fails with hash concatenation

closed-fixed
nobody
None
5
2014-08-21
2006-01-12
Anonymous
No

In FreeMarker 2.3.4, the following code

<#assign str = "{'id':'aa'} + {}" />
<#assign h2 = str?eval/>

fails with a StringIndexOutOfBoundsException:

java.lang.StringIndexOutOfBoundsException
at
java.lang.AbstractStringBuilder.delete(AbstractStringBuilder.java:705)
at java.lang.StringBuffer.delete(StringBuffer.java:374)
at
freemarker.template.Template.getSource(Template.java:487)
at
freemarker.core.TemplateObject.getSource(TemplateObject.java:167)
at
freemarker.core.TemplateObject.toString(TemplateObject.java:174)
at java.lang.String.valueOf(String.java:2577)
at java.lang.StringBuffer.append(StringBuffer.java:220)
at
freemarker.core.Expression.getStringValue(Expression.java:120)
at
freemarker.core.AddConcatExpression._getAsTemplateModel(AddConcatExpression.java:96)
at
freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at
freemarker.core.ParentheticalExpression._getAsTemplateModel(ParentheticalExpression.java:75)
at
freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at
freemarker.core.StringBuiltins$evalBI.calculateResult(StringBuiltins.java:173)
at
freemarker.core.StringBuiltins$StringBuiltIn._getAsTemplateModel(StringBuiltins.java:71)
at
freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Assignment.accept(Assignment.java:90)
at freemarker.core.Environment.visit(Environment.java:196)
at
freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:196)
at
freemarker.core.Environment.process(Environment.java:176)

However, this one wiht a single 'a' runs OK:

<#assign str = "{'id':'a'} + {}" />
<#assign h2 = str?eval/>

Regards

Discussion

    • status: open --> open-fixed
     
  • Logged In: YES
    user_id=33187

    A very strange little bug. It works now and the fix will be
    in the next release.

     
    • status: open-fixed --> closed-fixed
     
  • Logged In: YES
    user_id=546667

    Released with 2.3.5.