diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-02-13 14:37:17 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-02-13 14:37:17 +0000 |
| commit | e6740cb39c94bb404797e6baed7bcdf534c422ed (patch) | |
| tree | 292f108ee55eeb82af2188f6a0fbcec9a7dec12d | |
| parent | 0e5836dc0791127ce1b15e1063a41a52649507b7 (diff) | |
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
| -rw-r--r-- | django/template/defaultfilters.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/defaultfilters/tests.py | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 0ba16bc9a5..e6492dcd38 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -799,7 +799,7 @@ def filesizeformat(bytes): """ try: bytes = float(bytes) - except TypeError: + except (TypeError,ValueError,UnicodeDecodeError): return u"0 bytes" if bytes < 1024: diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index 4343586c48..0fe4673063 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -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'' |
