mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 21:14:01 +03:00
Merge pull request #2836 from ryangallen/master
only allow integer field to accept integers and strings, fixes #2835
This commit is contained in:
commit
5cc0a3c2a8
|
@ -682,7 +682,7 @@ class IntegerField(Field):
|
|||
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
|
||||
|
|
|
@ -549,10 +549,13 @@ class TestIntegerField(FieldValues):
|
|||
1: 1,
|
||||
0: 0,
|
||||
1.0: 1,
|
||||
0.0: 0
|
||||
0.0: 0,
|
||||
'1.0': 1
|
||||
}
|
||||
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 = {
|
||||
'1': 1,
|
||||
|
|
Loading…
Reference in New Issue
Block a user