Jason Sachs created FREEMARKER-68:
-------------------------------------

             Summary: 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