mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #4287 -- Fixed NaN and +/- Infinity handling in FloatField
NaN, +Inf, and -Inf are no longer valid values for FloatFields.
This commit is contained in:
committed by
Tim Graham
parent
cd4068f359
commit
cc957cb16c
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user