Fixed #11944 -- Improved exception handling for the filesizeformat filter. Thanks to rfk for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12426 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0e5836dc07
commit
e6740cb39c
|
@ -799,7 +799,7 @@ def filesizeformat(bytes):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
bytes = float(bytes)
|
bytes = float(bytes)
|
||||||
except TypeError:
|
except (TypeError,ValueError,UnicodeDecodeError):
|
||||||
return u"0 bytes"
|
return u"0 bytes"
|
||||||
|
|
||||||
if bytes < 1024:
|
if bytes < 1024:
|
||||||
|
|
|
@ -476,6 +476,15 @@ u'1024.0 MB'
|
||||||
>>> filesizeformat(1024*1024*1024)
|
>>> filesizeformat(1024*1024*1024)
|
||||||
u'1.0 GB'
|
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)
|
>>> pluralize(1)
|
||||||
u''
|
u''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue