Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #1176 -- Changed {% comment %} template tag not to generate a n…

…odelist, so it's now possible to comment-out broken template tags. Thanks, Kieran Holland

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1964 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 39639cfd22386856e4ee3cc9fe5e75c30bec066b 1 parent e702ec1
Adrian Holovaty adrianholovaty authored
7 django/core/template/__init__.py
View
@@ -311,6 +311,13 @@ def parse(self, parse_until=[]):
self.unclosed_block_tag(parse_until)
return nodelist
+ def skip_past(self, endtag):
+ while self.tokens:
+ token = self.next_token()
+ if token.token_type == TOKEN_BLOCK and token.contents == endtag:
+ return
+ self.unclosed_block_tag([endtag])
+
def create_variable_node(self, filter_expression):
return VariableNode(filter_expression)
3  django/core/template/defaulttags.py
View
@@ -286,8 +286,7 @@ def comment(parser, token):
"""
Ignore everything between ``{% comment %}`` and ``{% endcomment %}``
"""
- nodelist = parser.parse(('endcomment',))
- parser.delete_first_token()
+ parser.skip_past('endcomment')
return CommentNode()
comment = register.tag(comment)
5 tests/othertests/templates.py
View
@@ -144,6 +144,11 @@ def method(self):
'comment-tag01': ("{% comment %}this is hidden{% endcomment %}hello", {}, "hello"),
'comment-tag02': ("{% comment %}this is hidden{% endcomment %}hello{% comment %}foo{% endcomment %}", {}, "hello"),
+ # Comment tag can contain invalid stuff.
+ 'comment-tag03': ("foo{% comment %} {% if %} {% endcomment %}", {}, "foo"),
+ 'comment-tag04': ("foo{% comment %} {% endblock %} {% endcomment %}", {}, "foo"),
+ 'comment-tag05': ("foo{% comment %} {% somerandomtag %} {% endcomment %}", {}, "foo"),
+
### FOR TAG ###############################################################
'for-tag01': ("{% for val in values %}{{ val }}{% endfor %}", {"values": [1, 2, 3]}, "123"),
'for-tag02': ("{% for val in values reversed %}{{ val }}{% endfor %}", {"values": [1, 2, 3]}, "321"),
Please sign in to comment.
Something went wrong with that request. Please try again.