Django

Code

Changeset 6729

Show
Ignore:
Timestamp:
11/28/07 19:44:30 (1 year ago)
Author:
mtredinnick
Message:

Added tests and a small optimisation for [6721]. Thanks SmileyChris?. Fixed #6049

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/defaultfilters.py

    r6721 r6729  
    2626            args = list(args) 
    2727            args[0] = force_unicode(args[0]) 
    28         if isinstance(args[0], SafeData) and getattr(func, 'is_safe', False): 
    29             return mark_safe(func(*args, **kwargs)) 
     28            if isinstance(args[0], SafeData) and getattr(func, 'is_safe', False): 
     29                return mark_safe(func(*args, **kwargs)) 
    3030        return func(*args, **kwargs) 
    3131 
  • django/trunk/tests/regressiontests/templates/filters.py

    r6706 r6729  
    1212from django.utils.tzinfo import LocalTimezone 
    1313from django.utils.safestring import mark_safe 
     14 
     15# These two classes are used to test auto-escaping of __unicode__ output. 
     16class UnsafeClass: 
     17    def __unicode__(self): 
     18        return u'you & me' 
     19 
     20class SafeClass: 
     21    def __unicode__(self): 
     22        return mark_safe(u'you > me') 
    1423 
    1524# RESULT SYNTAX -- 
     
    228237        'chaining13': ('{{ a|safe|force_escape }}', {"a": "a < b"}, "a &lt; b"), 
    229238        'chaining14': ('{% autoescape off %}{{ a|safe|force_escape }}{% endautoescape %}', {"a": "a < b"}, "a &lt; b"), 
     239 
     240        # Filters decorated with stringfilter still respect is_safe.  
     241        'autoescape-stringfilter01': (r'{{ unsafe|capfirst }}', {'unsafe': UnsafeClass()}, 'You &amp; me'), 
     242        'autoescape-stringfilter02': (r'{% autoescape off %}{{ unsafe|capfirst }}{% endautoescape %}', {'unsafe': UnsafeClass()}, 'You & me'), 
     243        'autoescape-stringfilter03': (r'{{ safe|capfirst }}', {'safe': SafeClass()}, 'You &gt; me'), 
     244        'autoescape-stringfilter04': (r'{% autoescape off %}{{ safe|capfirst }}{% endautoescape %}', {'safe': SafeClass()}, 'You &gt; me'), 
    230245    } 
     246 
  • django/trunk/tests/regressiontests/templates/tests.py

    r6724 r6729  
    900900            # Literal string arguments to filters, if used in the result, are 
    901901            # safe. 
    902             'basic-syntax08': (r'{% autoescape on %}{{ var|default_if_none:" endquote\" hah" }}{% endautoescape %}', {"var": None}, ' endquote" hah'), 
     902            'autoescape-tag08': (r'{% autoescape on %}{{ var|default_if_none:" endquote\" hah" }}{% endautoescape %}', {"var": None}, ' endquote" hah'), 
     903 
     904            # Objects which return safe strings as their __unicode__ method 
     905            # won't get double-escaped. 
     906            'autoescape-tag09': (r'{{ unsafe }}', {'unsafe': filters.UnsafeClass()}, 'you &amp; me'), 
     907            'autoescape-tag10': (r'{{ safe }}', {'safe': filters.SafeClass()}, 'you &gt; me'), 
    903908 
    904909            # The "safe" and "escape" filters cannot work due to internal