Django

Code

Changeset 1964

Show
Ignore:
Timestamp:
01/14/06 18:48:23 (3 years ago)
Author:
adrian
Message:

Fixed #1176 -- Changed {% comment %} template tag not to generate a nodelist, so it's now possible to comment-out broken template tags. Thanks, Kieran Holland

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/template/defaulttags.py

    r1582 r1964  
    287287    Ignore everything between ``{% comment %}`` and ``{% endcomment %}`` 
    288288    """ 
    289     nodelist = parser.parse(('endcomment',)) 
    290     parser.delete_first_token() 
     289    parser.skip_past('endcomment') 
    291290    return CommentNode() 
    292291comment = register.tag(comment) 
  • django/trunk/django/core/template/__init__.py

    r1690 r1964  
    311311            self.unclosed_block_tag(parse_until) 
    312312        return nodelist 
     313 
     314    def skip_past(self, endtag): 
     315        while self.tokens: 
     316            token = self.next_token() 
     317            if token.token_type == TOKEN_BLOCK and token.contents == endtag: 
     318                return 
     319        self.unclosed_block_tag([endtag]) 
    313320 
    314321    def create_variable_node(self, filter_expression): 
  • django/trunk/tests/othertests/templates.py

    r1690 r1964  
    144144    'comment-tag01': ("{% comment %}this is hidden{% endcomment %}hello", {}, "hello"), 
    145145    'comment-tag02': ("{% comment %}this is hidden{% endcomment %}hello{% comment %}foo{% endcomment %}", {}, "hello"), 
     146 
     147    # Comment tag can contain invalid stuff. 
     148    'comment-tag03': ("foo{% comment %} {% if %} {% endcomment %}", {}, "foo"), 
     149    'comment-tag04': ("foo{% comment %} {% endblock %} {% endcomment %}", {}, "foo"), 
     150    'comment-tag05': ("foo{% comment %} {% somerandomtag %} {% endcomment %}", {}, "foo"), 
    146151 
    147152    ### FOR TAG ###############################################################