Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6014 -- More robust error handling when validating decimal fie…

…lds.

Thanks, pigletto.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6746 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 29892d02fa9c9ab3e48a18a143408abc3c88716e 1 parent 7a166f1
Malcolm Tredinnick authored November 29, 2007
4  django/newforms/fields.py
@@ -17,7 +17,7 @@
17 17
     from sets import Set as set
18 18
 
19 19
 from django.utils.translation import ugettext_lazy as _
20  
-from django.utils.encoding import StrAndUnicode, smart_unicode
  20
+from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str
21 21
 
22 22
 from util import ErrorList, ValidationError
23 23
 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput
@@ -235,7 +235,7 @@ def clean(self, value):
235 235
         super(DecimalField, self).clean(value)
236 236
         if not self.required and value in EMPTY_VALUES:
237 237
             return None
238  
-        value = str(value).strip()
  238
+        value = smart_str(value).strip()
239 239
         try:
240 240
             value = Decimal(value)
241 241
         except DecimalException:
4  tests/regressiontests/forms/fields.py
@@ -323,6 +323,10 @@
323 323
 Traceback (most recent call last):
324 324
 ...
325 325
 ValidationError: [u'Enter a number.']
  326
+>>> f.clean(u'łąść')
  327
+Traceback (most recent call last):
  328
+...
  329
+ValidationError: [u'Enter a number.']
326 330
 >>> f.clean('1.0 ')
327 331
 Decimal("1.0")
328 332
 >>> f.clean(' 1.0')

0 notes on commit 29892d0

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