Commit 1f10a39d by Ryan Allen

Match IntegerField validation with Django's, preventing decimal values being…

Match IntegerField validation with Django's, preventing decimal values being stored as ints, fixes #2835.

Match IntegerField validation with Django IntegerField, prevents decimal values being stored as ints, fixes #2835
 On branch master
parent ecb37f51
...@@ -682,7 +682,7 @@ class IntegerField(Field): ...@@ -682,7 +682,7 @@ class IntegerField(Field):
self.fail('max_string_length') self.fail('max_string_length')
try: try:
data = int(data) data = int(re.compile(r'\.0*\s*$').sub('', str(data)))
except (ValueError, TypeError): except (ValueError, TypeError):
self.fail('invalid') self.fail('invalid')
return data return data
......
...@@ -549,10 +549,13 @@ class TestIntegerField(FieldValues): ...@@ -549,10 +549,13 @@ class TestIntegerField(FieldValues):
1: 1, 1: 1,
0: 0, 0: 0,
1.0: 1, 1.0: 1,
0.0: 0 0.0: 0,
'1.0': 1
} }
invalid_inputs = { invalid_inputs = {
'abc': ['A valid integer is required.'] 0.5: ['A valid integer is required.'],
'abc': ['A valid integer is required.'],
'0.5': ['A valid integer is required.']
} }
outputs = { outputs = {
'1': 1, '1': 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment