Fixed #16676 -- Corrected the behavior of the 'add' template filter to return an empty string instead of the given value unchanged in the case of an invalid use. Thanks to dtrebbien for the report and to Aymeric Augustin for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16851 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Julien Phalip 2011-09-18 08:33:39 +00:00
parent 357910c1c6
commit 436aeb6e15
2 changed files with 5 additions and 5 deletions

View File

@ -665,8 +665,8 @@ def add(value, arg):
except (ValueError, TypeError): except (ValueError, TypeError):
try: try:
return value + arg return value + arg
except: except Exception:
return value return ''
add.is_safe = False add.is_safe = False
def get_digit(value, arg): def get_digit(value, arg):

View File

@ -346,10 +346,10 @@ def get_filter_tests():
#Ticket 9520: Make sure |date doesn't blow up on non-dates #Ticket 9520: Make sure |date doesn't blow up on non-dates
'date03': (r'{{ d|date:"m" }}', {'d': 'fail_string'}, ''), 'date03': (r'{{ d|date:"m" }}', {'d': 'fail_string'}, ''),
# Tests for #11687 # Tests for #11687 and #16676
'add01': (r'{{ i|add:"5" }}', {'i': 2000}, '2005'), 'add01': (r'{{ i|add:"5" }}', {'i': 2000}, '2005'),
'add02': (r'{{ i|add:"napis" }}', {'i': 2000}, '2000'), 'add02': (r'{{ i|add:"napis" }}', {'i': 2000}, ''),
'add03': (r'{{ i|add:16 }}', {'i': 'not_an_int'}, 'not_an_int'), 'add03': (r'{{ i|add:16 }}', {'i': 'not_an_int'}, ''),
'add04': (r'{{ i|add:"16" }}', {'i': 'not_an_int'}, 'not_an_int16'), 'add04': (r'{{ i|add:"16" }}', {'i': 'not_an_int'}, 'not_an_int16'),
'add05': (r'{{ l1|add:l2 }}', {'l1': [1, 2], 'l2': [3, 4]}, '[1, 2, 3, 4]'), 'add05': (r'{{ l1|add:l2 }}', {'l1': [1, 2], 'l2': [3, 4]}, '[1, 2, 3, 4]'),
'add06': (r'{{ t1|add:t2 }}', {'t1': (3, 4), 't2': (1, 2)}, '(3, 4, 1, 2)'), 'add06': (r'{{ t1|add:t2 }}', {'t1': (3, 4), 't2': (1, 2)}, '(3, 4, 1, 2)'),