mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-01 22:14:06 +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')
|
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):
|
||||||
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,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user