Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Raises an exception if a tag has no start.

  • Loading branch information...
commit 3071c14b85778c3c364b9d2929ef2766f6de2698 1 parent e5f8f04
@BertrandBordage authored
Showing with 11 additions and 4 deletions.
  1. +2 −1  README.rst
  2. +9 −3 terms/html.py
View
3  README.rst
@@ -312,7 +312,8 @@ HTMLValidationWarning
work anyway.
:Reason: This happens when django-terms finds a problem in the architecture
of the current HTML page.
-:Encountered: If you forget the final ``/`` of a “start-end” tag.
+:Encountered: If your HTML page is malformed; if you forget a start tag,
+ an end tag, or the final ``/`` of a “start-end” tag.
View
12 terms/html.py
@@ -91,9 +91,15 @@ def handle_starttag(self, tag, attrs):
self.disabled_level = self.tree_level
def handle_endtag(self, tag):
- NeutralHTMLReconstructor.handle_endtag(self, tag)
-
- opened_tag, full_start_tag = self.opened_tags.pop()
+ try:
+ opened_tag, full_start_tag = self.opened_tags.pop()
+ # Adds the tag to HTML only if it has a start tag.
+ NeutralHTMLReconstructor.handle_endtag(self, tag)
+ except IndexError:
+ if settings.DEBUG:
+ raise HTMLValidationWarning('unable to find the start tag '
+ 'for </%s>' % tag)
+ return None
if tag != opened_tag:
if settings.DEBUG:
raise HTMLValidationWarning('unable to find the end tag for '
Please sign in to comment.
Something went wrong with that request. Please try again.