diff options
author | Russell Keith-Magee <russell@keith-magee.com> | 2010-02-22 14:38:44 +0000 |
---|---|---|
committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-02-22 14:38:44 +0000 |
commit | 692fd7da5e5bfe1533c40f94999ea42f9b986356 (patch) | |
tree | d678b6181caacef71201a4606571f8f6b918237d /django/forms/fields.py | |
parent | e6db084ac8fdf04ba20b5976a1cebfb77d55c97e (diff) | |
download | django-692fd7da5e5bfe1533c40f94999ea42f9b986356.tar.gz |
Fixed #7777 -- Added validation handling for NaN, Inf and -Inf in DecimalFields. Thanks to thebitguru for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12490 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/fields.py')
-rw-r--r-- | django/forms/fields.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index f5f3abf49d..dd5ae1e427 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -283,6 +283,11 @@ class DecimalField(Field): super(DecimalField, self).validate(value) if value in validators.EMPTY_VALUES: return + # Check for NaN, Inf and -Inf values. We can't compare directly for NaN, + # since it is never equal to itself. However, NaN is the only value that + # isn't equal to itself, so we can use this to identify NaN + if value != value or value == Decimal("Inf") or value == Decimal("-Inf"): + raise ValidationError(self.error_messages['invalid']) sign, digittuple, exponent = value.as_tuple() decimals = abs(exponent) # digittuple doesn't include any leading zeros. @@ -467,7 +472,7 @@ class ImageField(FileField): f = super(ImageField, self).to_python(data) if f is None: return None - + # Try to import PIL in either of the two ways it can end up installed. try: from PIL import Image @@ -584,7 +589,7 @@ class ChoiceField(Field): def __init__(self, choices=(), required=True, widget=None, label=None, initial=None, help_text=None, *args, **kwargs): - super(ChoiceField, self).__init__(required=required, widget=widget, label=label, + super(ChoiceField, self).__init__(required=required, widget=widget, label=label, initial=initial, help_text=help_text, *args, **kwargs) self.choices = choices |