Skip to content

Commit

Permalink
only allow integer field to accept integers and strings, fixes encode…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Allen committed Apr 17, 2015
1 parent ecb37f5 commit 6d4c85f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def to_internal_value(self, data):
self.fail('max_string_length')

try:
data = int(data)
data = int(re.compile(r'\.0*\s*$').sub('', str(data)))
except (ValueError, TypeError):
self.fail('invalid')
return data
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ class TestIntegerField(FieldValues):
0.0: 0
}
invalid_inputs = {
'abc': ['A valid integer is required.']
'abc': ['A valid integer is required.'],
0.5: ['A valid integer is required.']
}
outputs = {
'1': 1,
Expand Down

0 comments on commit 6d4c85f

Please sign in to comment.