summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-02-13 14:44:07 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-02-13 14:44:07 +0000
commit166405b2e4197fba7d5638ee732f2170f8647f62 (patch)
treebdc69d1cf37e925c7d66a7b371afce945588745f
parentf30a4b368cd6a03dfbbfd2145d06f747664ece86 (diff)
[1.1.X] Fixed #11944 -- Improved exception handling for the filesizeformat filter. Thanks to rfk for the report and patch.
Backport of r12426 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12428 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/defaultfilters.py2
-rw-r--r--tests/regressiontests/defaultfilters/tests.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index a8c25670f6..03a294bc28 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -792,7 +792,7 @@ def filesizeformat(bytes):
"""
try:
bytes = float(bytes)
- except TypeError:
+ except (TypeError,ValueError,UnicodeDecodeError):
return u"0 bytes"
if bytes < 1024:
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index 4343586c48..0fe4673063 100644
--- a/tests/regressiontests/defaultfilters/tests.py
+++ b/tests/regressiontests/defaultfilters/tests.py
@@ -476,6 +476,15 @@ u'1024.0 MB'
>>> filesizeformat(1024*1024*1024)
u'1.0 GB'
+>>> filesizeformat(complex(1,-1))
+u'0 bytes'
+
+>>> filesizeformat("")
+u'0 bytes'
+
+>>> filesizeformat(u"\N{GREEK SMALL LETTER ALPHA}")
+u'0 bytes'
+
>>> pluralize(1)
u''