diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-02-13 14:44:07 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-02-13 14:44:07 +0000 |
| commit | 166405b2e4197fba7d5638ee732f2170f8647f62 (patch) | |
| tree | bdc69d1cf37e925c7d66a7b371afce945588745f | |
| parent | f30a4b368cd6a03dfbbfd2145d06f747664ece86 (diff) | |
[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
| -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 a8c25670f6..03a294bc28 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -792,7 +792,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'' |
