Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11944 -- Improved exception handling for the filesizeformat fi…

…lter. Thanks to rfk for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12426 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e6740cb39c94bb404797e6baed7bcdf534c422ed 1 parent 0e5836d
Russell Keith-Magee authored February 13, 2010
2  django/template/defaultfilters.py
@@ -799,7 +799,7 @@ def filesizeformat(bytes):
799 799
     """
800 800
     try:
801 801
         bytes = float(bytes)
802  
-    except TypeError:
  802
+    except (TypeError,ValueError,UnicodeDecodeError):
803 803
         return u"0 bytes"
804 804
 
805 805
     if bytes < 1024:
9  tests/regressiontests/defaultfilters/tests.py
@@ -476,6 +476,15 @@
476 476
 >>> filesizeformat(1024*1024*1024)
477 477
 u'1.0 GB'
478 478
 
  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
+
479 488
 >>> pluralize(1)
480 489
 u''
481 490
 

0 notes on commit e6740cb

Please sign in to comment.
Something went wrong with that request. Please try again.