Commit 166405b2 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

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

[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
parent f30a4b36
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -792,7 +792,7 @@ def filesizeformat(bytes):
    """
    try:
        bytes = float(bytes)
    except TypeError:
    except (TypeError,ValueError,UnicodeDecodeError):
        return u"0 bytes"

    if bytes < 1024:
+9 −0
Original line number Diff line number Diff line
@@ -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''