Fixed #6492 -- Added bullet-proofing to isValidFloat validator. Thanks, Bastian Kleineidam.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7258 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2008-03-17 14:05:43 +00:00
parent 30bdabb2b0
commit 50ecd75379
2 changed files with 9 additions and 3 deletions

View File

@ -18,7 +18,7 @@ except ImportError:
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext as _, ugettext_lazy, ungettext from django.utils.translation import ugettext as _, ugettext_lazy, ungettext
from django.utils.functional import Promise, lazy from django.utils.functional import Promise, lazy
from django.utils.encoding import force_unicode from django.utils.encoding import force_unicode, smart_str
_datere = r'\d{4}-\d{1,2}-\d{1,2}' _datere = r'\d{4}-\d{1,2}-\d{1,2}'
_timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?' _timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?'
@ -451,7 +451,7 @@ class IsValidDecimal(object):
"Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places "Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places
def isValidFloat(field_data, all_data): def isValidFloat(field_data, all_data):
data = str(field_data) data = smart_str(field_data)
try: try:
float(data) float(data)
except ValueError: except ValueError:

View File

@ -1,3 +1,4 @@
# coding: utf-8
""" """
27. Default manipulators 27. Default manipulators
@ -21,7 +22,7 @@ class Album(models.Model):
def __unicode__(self): def __unicode__(self):
return self.name return self.name
__test__ = {'API_TESTS':""" __test__ = {'API_TESTS':u"""
>>> from django.utils.datastructures import MultiValueDict >>> from django.utils.datastructures import MultiValueDict
# Create a Musician object via the default AddManipulator. # Create a Musician object via the default AddManipulator.
@ -88,4 +89,9 @@ True
<Album: Ultimate Ella> <Album: Ultimate Ella>
>>> a2.release_date >>> a2.release_date
datetime.date(2005, 2, 13) datetime.date(2005, 2, 13)
# Test isValidFloat Unicode coercion
>>> from django.core.validators import isValidFloat, ValidationError
>>> try: isValidFloat(u"ä", None)
... except ValidationError: pass
"""} """}