Merge pull request #2836 from ryangallen/master

only allow integer field to accept integers and strings, fixes #2835
This commit is contained in:
Kevin Brown 2015-04-20 18:10:40 -04:00
commit 5cc0a3c2a8
2 changed files with 6 additions and 3 deletions

View File

@ -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

View File

@ -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,