Code

Ticket #3100: 3100-alternate.diff

File 3100-alternate.diff, 1.3 KB (added by SmileyChris, 3 years ago)

An alternative to adding a parse_until_args_allowed argument

Line 
1diff --git a/django/template/base.py b/django/template/base.py
2index eacc29c..a315c05 100644
3--- a/django/template/base.py
4+++ b/django/template/base.py
5@@ -222,10 +222,16 @@ class Parser(object):
6                 var_node = self.create_variable_node(filter_expression)
7                 self.extend_nodelist(nodelist, var_node,token)
8             elif token.token_type == TOKEN_BLOCK:
9-                if token.contents in parse_until:
10-                    # put token back on token list so calling code knows why it terminated
11-                    self.prepend_token(token)
12-                    return nodelist
13+                for value in parse_until:
14+                    # A parse_until value which ends in a ' ' will match any
15+                    # token starting with that value, otherwise an exact match
16+                    # is required.
17+                    if (value == token.contents or value.endswith(' ')
18+                            and token.contents.startswith(value)):
19+                        # Put token back on token list so calling code knows
20+                        # why it terminated.
21+                        self.prepend_token(token)
22+                        return nodelist
23                 try:
24                     command = token.contents.split()[0]
25                 except IndexError: