Ticket #8902: with_patch_test.diff

File with_patch_test.diff, 1.9 KB (added by kire, 7 years ago)

Patch + tests

  • django/template/defaulttags.py

     
    11231123            {{ total }} object{{ total|pluralize }}
    11241124        {% endwith %}
    11251125    """
    1126     bits = list(token.split_contents())
    1127     if len(bits) != 4 or bits[2] != "as":
     1126    bits = list(token.contents.split())
     1127    if bits[-2] != "as":
    11281128        raise TemplateSyntaxError("%r expected format is 'value as name'" %
    11291129                                  bits[0])
    1130     var = parser.compile_filter(bits[1])
    1131     name = bits[3]
     1130   
     1131    var = parser.compile_filter(' '.join(bits[1:-2]))
     1132    name = bits[-1]
    11321133    nodelist = parser.parse(('endwith',))
    11331134    parser.delete_first_token()
    11341135    return WithNode(var, name, nodelist)
  • tests/regressiontests/templates/tests.py

     
    877877            ### WITH TAG ########################################################
    878878            'with01': ('{% with dict.key as key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, '50'),
    879879            'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')),
    880 
     880            'with03': ('{% with input|cut:" " as cutted %}{{ cutted }}{% endwith %}', {'input': 'string with spaces'}, 'stringwithspaces'),
     881           
    881882            'with-error01': ('{% with dict.key xx key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError),
    882883            'with-error02': ('{% with dict.key as %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError),
    883884
Back to Top