Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.1.X] Fixed #11944 -- Improved exception handling for the filesizef…

…ormat 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
  • Loading branch information...
commit 166405b2e4197fba7d5638ee732f2170f8647f62 1 parent f30a4b3
@freakboy3742 freakboy3742 authored
View
2  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:
View
9 tests/regressiontests/defaultfilters/tests.py
@@ -476,6 +476,15 @@
>>> 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''
Please sign in to comment.
Something went wrong with that request. Please try again.