From 50ecd7537909915bc5faed644817a58c0a1f765e Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 17 Mar 2008 14:05:43 +0000 Subject: [PATCH] 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 --- django/core/validators.py | 4 ++-- tests/modeltests/manipulators/models.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/django/core/validators.py b/django/core/validators.py index 874edaefdd..e728dbc0ed 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -18,7 +18,7 @@ except ImportError: from django.conf import settings from django.utils.translation import ugettext as _, ugettext_lazy, ungettext 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}' _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 def isValidFloat(field_data, all_data): - data = str(field_data) + data = smart_str(field_data) try: float(data) except ValueError: diff --git a/tests/modeltests/manipulators/models.py b/tests/modeltests/manipulators/models.py index 2ee81f62b3..c9b9848235 100644 --- a/tests/modeltests/manipulators/models.py +++ b/tests/modeltests/manipulators/models.py @@ -1,3 +1,4 @@ +# coding: utf-8 """ 27. Default manipulators @@ -21,7 +22,7 @@ class Album(models.Model): def __unicode__(self): return self.name -__test__ = {'API_TESTS':""" +__test__ = {'API_TESTS':u""" >>> from django.utils.datastructures import MultiValueDict # Create a Musician object via the default AddManipulator. @@ -88,4 +89,9 @@ True >>> a2.release_date datetime.date(2005, 2, 13) + +# Test isValidFloat Unicode coercion +>>> from django.core.validators import isValidFloat, ValidationError +>>> try: isValidFloat(u"รค", None) +... except ValidationError: pass """}