From 5d1d054e150bace05b8826d990d71c46834eef87 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 29 Nov 2007 20:10:00 +0000 Subject: [PATCH] Fixed #6030 -- More robust error handling for the "float" filter. Thanks, SmileyChris. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6752 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/defaultfilters.py | 2 +- tests/regressiontests/defaultfilters/tests.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index ca03ff87e32..f2be64ef1d5 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -91,7 +91,7 @@ def floatformat(text, arg=-1): """ try: f = float(text) - except ValueError: + except (ValueError, TypeError): return u'' try: d = int(arg) diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index 26d448900df..bfa03cd6e18 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -37,6 +37,8 @@ u'' u'13.1031' >>> floatformat(u'foo', u'bar') u'' +>>> floatformat(None) +u'' >>> addslashes(u'"double quotes" and \'single quotes\'') u'\\"double quotes\\" and \\\'single quotes\\\''