Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.1.X] Fixed #7777 -- Added validation handling for NaN, Inf and -In…

…f in DecimalFields. Thanks to thebitguru for the patch.

Backport of r12490 from trunk.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8b415e7299aebd0c4109925d8fe366734810413a 1 parent 9ee2d5c
@freakboy3742 freakboy3742 authored
Showing with 18 additions and 0 deletions.
  1. +6 −0 django/forms/
  2. +12 −0 tests/regressiontests/forms/
6 django/forms/
@@ -240,6 +240,12 @@ def clean(self, value):
except DecimalException:
raise ValidationError(self.error_messages['invalid'])
+ # 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.
12 tests/regressiontests/forms/
@@ -320,6 +320,18 @@
>>> f.clean(Decimal('3.14')) == Decimal("3.14")
+>>> f.clean('NaN')
+Traceback (most recent call last):
+ValidationError: [u'Enter a number.']
+>>> f.clean('Inf')
+Traceback (most recent call last):
+ValidationError: [u'Enter a number.']
+>>> f.clean('-Inf')
+Traceback (most recent call last):
+ValidationError: [u'Enter a number.']
>>> f.clean('a')
Traceback (most recent call last):
Please sign in to comment.
Something went wrong with that request. Please try again.