Code

Ticket #8902: with_patch_test.diff

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

Patch + tests

Line 
1Index: django/template/defaulttags.py
2===================================================================
3--- django/template/defaulttags.py      (revision 8969)
4+++ django/template/defaulttags.py      (working copy)
5@@ -1123,12 +1123,13 @@
6             {{ total }} object{{ total|pluralize }}
7         {% endwith %}
8     """
9-    bits = list(token.split_contents())
10-    if len(bits) != 4 or bits[2] != "as":
11+    bits = list(token.contents.split())
12+    if bits[-2] != "as":
13         raise TemplateSyntaxError("%r expected format is 'value as name'" %
14                                   bits[0])
15-    var = parser.compile_filter(bits[1])
16-    name = bits[3]
17+   
18+    var = parser.compile_filter(' '.join(bits[1:-2]))
19+    name = bits[-1]
20     nodelist = parser.parse(('endwith',))
21     parser.delete_first_token()
22     return WithNode(var, name, nodelist)
23Index: tests/regressiontests/templates/tests.py
24===================================================================
25--- tests/regressiontests/templates/tests.py    (revision 8969)
26+++ tests/regressiontests/templates/tests.py    (working copy)
27@@ -877,7 +877,8 @@
28             ### WITH TAG ########################################################
29             'with01': ('{% with dict.key as key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, '50'),
30             'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')),
31-
32+            'with03': ('{% with input|cut:" " as cutted %}{{ cutted }}{% endwith %}', {'input': 'string with spaces'}, 'stringwithspaces'),
33+           
34             'with-error01': ('{% with dict.key xx key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError),
35             'with-error02': ('{% with dict.key as %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError),
36