[ 
https://issues.apache.org/jira/browse/FREEMARKER-68?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16122316#comment-16122316
 ] 

Jason Sachs edited comment on FREEMARKER-68 at 8/10/17 8:59 PM:
----------------------------------------------------------------

Looks like essentially {{voodooDoll.hit??}} is translated into a lookup of 
{{voodooDoll['hit']}} rather than checking something equivalent to {{if 'hit' 
in voodooDoll or hasattr(voodooDoll,'hit')}} (with appropriate 
exception-handling if the first {{in}} test fails)


was (Author: jms_nh):
Looks like essentially {{voodooDoll.hit??}} is translated into a lookup of 
{{voodooDoll['hit']}} rather than checking something equivalent to {{if 'hit' 
in voodooDoll or hasattr(voodooDoll,'hit')}} (with appropriate 
exception-handling if the first {{in}} test fails

> Double-question mark operator does not properly test for attributes
> -------------------------------------------------------------------
>
>                 Key: FREEMARKER-68
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-68
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.23
>            Reporter: Jason Sachs
>
> The double-question mark operator doesn't work properly with some Jython 
> objects.
> It works properly with dicts.
> It does not work properly with custom classes and triggers an item lookup.
> Example setup: (I can't post a complete self-contained example, sorry)
> Jython code called before FreeMarker template is rendered:
> {code}
> class VoodooDoll(object):
>     def pinch(self):
>         return "ouch"
> model['test1'] = dict(voodooDoll=VoodooDoll())
> {code}
> FreeMarker template:
> {code}
> <#if test1.blah??>
> blah present
> </#if>
> <#if test1.voodooDoll??>
> voodoo doll present
> </#if>
> <#if test1.voodooDoll.pinch??>
> voodoo doll pinch present
> </#if>
> <#if test1.voodooDoll.hit??>
> voodoo doll hit present
> </#if>
> {code}
> This produces the output
> {noformat}
> voodoo doll present
> voodoo doll pinch present
> {noformat}
> so the first three {{#if}} tests work properly, but the fourth one causes 
> this error:
> {noformat}
>       - Failed at: #if test1.voodooDoll.hit??  [in template 
> "source\\aux-files\\parameters.html.template" at line 58, column 1]
> ...
> Caused by: TypeError: 'VoodooDoll' object is unsubscriptable
>       at org.python.core.Py.TypeError(Py.java:235)
>       at org.python.core.PyObject.__finditem__(PyObject.java:585)
>       at 
> org.python.core.PyObjectDerived.__finditem__(PyObjectDerived.java:861)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to