Skip to content

Commit

Permalink
Fixed #486 -- Fixed bug in template filter parsing in edge cases, and…
Browse files Browse the repository at this point in the history
… added unit tests. Thanks, Simon

git-svn-id: http://code.djangoproject.com/svn/django/trunk@634 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Sep 11, 2005
1 parent e01ef9d commit 095305c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django/core/template.py
Expand Up @@ -295,13 +295,14 @@ def read_filters(self):
if registered_filters[filter_name][1] == True and arg is None: if registered_filters[filter_name][1] == True and arg is None:
raise TemplateSyntaxError, "Filter '%s' requires an argument" % filter_name raise TemplateSyntaxError, "Filter '%s' requires an argument" % filter_name
if registered_filters[filter_name][1] == False and arg is not None: if registered_filters[filter_name][1] == False and arg is not None:
raise TemplateSyntaxError, "Filter '%s' should not have an argument" % filter_name raise TemplateSyntaxError, "Filter '%s' should not have an argument (argument is %r)" % (filter_name, arg)
self.filters.append((filter_name, arg)) self.filters.append((filter_name, arg))
if self.current is None: if self.current is None:
break break


def read_filter(self): def read_filter(self):
self.current_filter_name = self.read_alphanumeric_token() self.current_filter_name = self.read_alphanumeric_token()
self.current_filter_arg = None
# Have we reached the end? # Have we reached the end?
if self.current is None: if self.current is None:
return (self.current_filter_name, None) return (self.current_filter_name, None)
Expand Down
3 changes: 3 additions & 0 deletions tests/othertests/templates.py
Expand Up @@ -92,6 +92,9 @@ def method(self):
# Raise TemplateSyntaxError for empty block tags # Raise TemplateSyntaxError for empty block tags
'basic-syntax28': ("{% %}", {}, template.TemplateSyntaxError), 'basic-syntax28': ("{% %}", {}, template.TemplateSyntaxError),


# Chained filters, with an argument to the first one
'basic-syntax29': ('{{ var|removetags:"b i"|upper|lower }}', {"var": "<b><i>Yes</i></b>"}, "yes"),

### IF TAG ################################################################ ### IF TAG ################################################################
'if-tag01': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": True}, "yes"), 'if-tag01': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": True}, "yes"),
'if-tag02': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": False}, "no"), 'if-tag02': ("{% if foo %}yes{% else %}no{% endif %}", {"foo": False}, "no"),
Expand Down

0 comments on commit 095305c

Please sign in to comment.