diff options
| author | Daniel Langer <daniel@langer.me> | 2013-09-06 16:54:48 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-09-06 14:56:37 -0400 |
| commit | cc957cb16cfdad7e6c9e97dc885fc415abbf5eaa (patch) | |
| tree | 6cdb547c40c6875628d870b1d2b6f19f509e5897 /django/forms | |
| parent | cd4068f35900f22d0384717db0dd7b882d72a4f9 (diff) | |
Fixed #4287 -- Fixed NaN and +/- Infinity handling in FloatField
NaN, +Inf, and -Inf are no longer valid values for FloatFields.
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/fields.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index c06352a964..7a59a3d664 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -279,6 +279,15 @@ class FloatField(IntegerField): raise ValidationError(self.error_messages['invalid'], code='invalid') return value + def validate(self, value): + super(FloatField, self).validate(value) + + # Check for NaN (which is the only thing not equal to itself) and +/- infinity + if value != value or value in (Decimal('Inf'), Decimal('-Inf')): + raise ValidationError(self.error_messages['invalid'], code='invalid') + + return value + def widget_attrs(self, widget): attrs = super(FloatField, self).widget_attrs(widget) if isinstance(widget, NumberInput): |
