Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16676 -- Corrected the behavior of the 'add' template filter t…

…o 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
  • Loading branch information...
commit 436aeb6e1513085d09e33683cd0f60ee4fb746a7 1 parent 357910c
Julien Phalip authored September 18, 2011
4  django/template/defaultfilters.py
@@ -665,8 +665,8 @@ def add(value, arg):
665 665
     except (ValueError, TypeError):
666 666
         try:
667 667
             return value + arg
668  
-        except:
669  
-            return value
  668
+        except Exception:
  669
+            return ''
670 670
 add.is_safe = False
671 671
 
672 672
 def get_digit(value, arg):
6  tests/regressiontests/templates/filters.py
@@ -346,10 +346,10 @@ def get_filter_tests():
346 346
         #Ticket 9520: Make sure |date doesn't blow up on non-dates
347 347
         'date03': (r'{{ d|date:"m" }}', {'d': 'fail_string'}, ''),
348 348
 
349  
-         # Tests for #11687
  349
+         # Tests for #11687 and #16676
350 350
          'add01': (r'{{ i|add:"5" }}', {'i': 2000}, '2005'),
351  
-         'add02': (r'{{ i|add:"napis" }}', {'i': 2000}, '2000'),
352  
-         'add03': (r'{{ i|add:16 }}', {'i': 'not_an_int'}, 'not_an_int'),
  351
+         'add02': (r'{{ i|add:"napis" }}', {'i': 2000}, ''),
  352
+         'add03': (r'{{ i|add:16 }}', {'i': 'not_an_int'}, ''),
353 353
          'add04': (r'{{ i|add:"16" }}', {'i': 'not_an_int'}, 'not_an_int16'),
354 354
          'add05': (r'{{ l1|add:l2 }}', {'l1': [1, 2], 'l2': [3, 4]}, '[1, 2, 3, 4]'),
355 355
          'add06': (r'{{ t1|add:t2 }}', {'t1': (3, 4), 't2': (1, 2)}, '(3, 4, 1, 2)'),

0 notes on commit 436aeb6

Please sign in to comment.
Something went wrong with that request. Please try again.