Skip to content

Commit 166405b

Browse files
committed
[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
1 parent f30a4b3 commit 166405b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

django/template/defaultfilters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def filesizeformat(bytes):
792792
"""
793793
try:
794794
bytes = float(bytes)
795-
except TypeError:
795+
except (TypeError,ValueError,UnicodeDecodeError):
796796
return u"0 bytes"
797797

798798
if bytes < 1024:

tests/regressiontests/defaultfilters/tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,15 @@
476476
>>> filesizeformat(1024*1024*1024)
477477
u'1.0 GB'
478478
479+
>>> filesizeformat(complex(1,-1))
480+
u'0 bytes'
481+
482+
>>> filesizeformat("")
483+
u'0 bytes'
484+
485+
>>> filesizeformat(u"\N{GREEK SMALL LETTER ALPHA}")
486+
u'0 bytes'
487+
479488
>>> pluralize(1)
480489
u''
481490

0 commit comments

Comments
 (0)