freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Sachs (JIRA)" <>
Subject [jira] [Created] (FREEMARKER-68) Double-question mark operator does not properly test for attributes
Date Thu, 10 Aug 2017 20:57:00 GMT
Jason Sachs created FREEMARKER-68:

             Summary: Double-question mark operator does not properly test for attributes
                 Key: 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:

class VoodooDoll(object):
    def pinch(self):
        return "ouch"

model['test1'] = dict(voodooDoll=VoodooDoll())

FreeMarker template:
<#if test1.blah??>
blah present
<#if test1.voodooDoll??>
voodoo doll present
<#if test1.voodooDoll.pinch??>
voodoo doll pinch present
<#if test1.voodooDoll.hit??>
voodoo doll hit present

This produces the output

voodoo doll present
voodoo doll pinch present

so the first three {{#if}} tests work properly, but the fourth one causes this error:

	- 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(

	at org.python.core.PyObject.__finditem__(

	at org.python.core.PyObjectDerived.__finditem__(

This message was sent by Atlassian JIRA

View raw message