Skip to content

Commit

Permalink
Fixed #11944 -- Improved exception handling for the filesizeformat fi…
Browse files Browse the repository at this point in the history
…lter. Thanks to rfk for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12426 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed Feb 13, 2010
1 parent 0e5836d commit e6740cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/template/defaultfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def filesizeformat(bytes):
"""
try:
bytes = float(bytes)
except TypeError:
except (TypeError,ValueError,UnicodeDecodeError):
return u"0 bytes"

if bytes < 1024:
Expand Down
9 changes: 9 additions & 0 deletions tests/regressiontests/defaultfilters/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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''
Expand Down

0 comments on commit e6740cb

Please sign in to comment.