Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #9520: make the date filter fail silently for non-date values. …

…Thanks, Andrew Badr and Eric Holscher.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10365 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9828557731072ccc5734bed520d6efcde620dc1d 1 parent ef9bedf
@jacobian jacobian authored
View
10 django/template/defaultfilters.py
@@ -681,7 +681,10 @@ def date(value, arg=None):
return u''
if arg is None:
arg = settings.DATE_FORMAT
- return format(value, arg)
+ try:
+ return format(value, arg)
+ except AttributeError:
+ return ''
date.is_safe = False
def time(value, arg=None):
@@ -691,7 +694,10 @@ def time(value, arg=None):
return u''
if arg is None:
arg = settings.TIME_FORMAT
- return time_format(value, arg)
+ try:
+ return time_format(value, arg)
+ except AttributeError:
+ return ''
time.is_safe = False
def timesince(value, arg=None):
View
6 tests/regressiontests/templates/filters.py
@@ -320,4 +320,10 @@ def get_filter_tests():
'join02': (r'{% autoescape off %}{{ a|join:", " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha, beta & me'),
'join03': (r'{{ a|join:" & " }}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'),
'join04': (r'{% autoescape off %}{{ a|join:" & " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha & beta & me'),
+
+
+ 'date01': (r'{{ d|date:"m" }}', {'d': datetime(2008, 1, 1)}, '01'),
+ 'date02': (r'{{ d|date }}', {'d': datetime(2008, 1, 1)}, 'Jan. 1, 2008'),
+ #Ticket 9520: Make sure |date doesn't blow up on non-dates
+ 'date03': (r'{{ d|date:"m" }}', {'d': 'fail_string'}, ''),
}
Please sign in to comment.
Something went wrong with that request. Please try again.