We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 605369e + 32acc4a commit 0ca1145Copy full SHA for 0ca1145
rest_framework/fields.py
@@ -665,6 +665,7 @@ class IntegerField(Field):
665
'max_string_length': _('String value too large.')
666
}
667
MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
668
+ re_decimal = re.compile(r'\.0*\s*$') # allow e.g. '1.0' as an int, but not '1.2'
669
670
def __init__(self, **kwargs):
671
self.max_value = kwargs.pop('max_value', None)
@@ -682,7 +683,7 @@ def to_internal_value(self, data):
682
683
self.fail('max_string_length')
684
685
try:
- data = int(re.compile(r'\.0*\s*$').sub('', str(data)))
686
+ data = int(self.re_decimal.sub('', str(data)))
687
except (ValueError, TypeError):
688
self.fail('invalid')
689
return data
0 commit comments