Ticket #12554: r12819_with_tests.diff

File r12819_with_tests.diff, 2.7 KB (added by Colin Copeland, 14 years ago)

add patch with tests

  • django/template/__init__.py

     
    570570                if not lookup:
    571571                    arg_vals.append(mark_safe(arg))
    572572                else:
    573                     arg_vals.append(arg.resolve(context))
     573                    try:
     574                        arg_vals.append(arg.resolve(context))
     575                    except VariableDoesNotExist:
     576                        arg_vals.append(settings.TEMPLATE_STRING_IF_INVALID)
    574577            if getattr(func, 'needs_autoescape', False):
    575578                new_obj = func(obj, autoescape=context.autoescape, *arg_vals)
    576579            else:
     
    745748                            TypeError,  # unsubscriptable object
    746749                            ):
    747750                        raise VariableDoesNotExist("Failed lookup for key [%s] in %r", (bit, current)) # missing attribute
    748                 except Exception, e:
    749                     if getattr(e, 'silent_variable_failure', False):
    750                         current = settings.TEMPLATE_STRING_IF_INVALID
    751                     else:
    752                         raise
     751            except Exception, e:
     752                if getattr(e, 'silent_variable_failure', False):
     753                    current = settings.TEMPLATE_STRING_IF_INVALID
     754                else:
     755                    raise
    753756
    754757        return current
    755758
  • tests/regressiontests/templates/tests.py

     
    9797    def method(self):
    9898        return "OtherClass.method"
    9999
     100class SilentGetItemClass(object):
     101    def __getitem__(self, key):
     102        raise SomeException
     103
    100104class UTF8Class:
    101105    "Class whose __str__ returns non-ASCII data"
    102106    def __str__(self):
     
    552556            #filters should accept empty string constants
    553557            'filter-syntax20': ('{{ ""|default_if_none:"was none" }}', {}, ""),
    554558
     559            # regression tests for ticket #12554
     560            'filter-syntax21': ("{{ a.b }}", {'a': SilentGetItemClass()}, ('', 'INVALID')),
     561            'filter-syntax22': ("{{ a|default:notreal }}", {'a': 'test'}, ('test', 'test')),
     562            'filter-syntax23': ("{{ a|default:notreal }}", {'a': ''}, ('', 'INVALID')),
     563
    555564            ### COMMENT SYNTAX ########################################################
    556565            'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"),
    557566            'comment-syntax02': ("{# this is hidden #}hello{# foo #}", {}, "hello"),
Back to Top