Ticket #10912: firstof_autoescape_t10912_r10630.diff

File firstof_autoescape_t10912_r10630.diff, 1.9 KB (added by andrewbadr, 6 years ago)

Fix, with test

  • django/template/defaulttags.py

     
    1010
    1111from django.template import Node, NodeList, Template, Context, Variable
    1212from django.template import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END
    13 from django.template import get_library, Library, InvalidTemplateLibrary
     13from django.template import get_library, Library, InvalidTemplateLibrary, _render_value_in_context
    1414from django.conf import settings
    15 from django.utils.encoding import smart_str, smart_unicode
     15from django.utils.encoding import smart_str
    1616from django.utils.itercompat import groupby
    1717from django.utils.safestring import mark_safe
    1818
     
    7676        for var in self.vars:
    7777            value = var.resolve(context, True)
    7878            if value:
    79                 return smart_unicode(value)
     79                return _render_value_in_context(value, context)
    8080        return u''
    8181
    8282class ForNode(Node):
  • tests/regressiontests/templates/tests.py

     
    501501            'firstof07': ('{% firstof a b "c" %}', {'a':0}, 'c'),
    502502            'firstof08': ('{% firstof a b "c and d" %}', {'a':0,'b':0}, 'c and d'),
    503503            'firstof09': ('{% firstof %}', {}, template.TemplateSyntaxError),
     504            'firstof10': ('{% firstof a %}', {'a': '<'}, '&lt;'),
    504505
    505506            ### FOR TAG ###############################################################
    506507            'for-tag01': ("{% for val in values %}{{ val }}{% endfor %}", {"values": [1, 2, 3]}, "123"),
Back to Top