mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Set IntegerField class variable for compiled decimal regex, comment for purpose
This commit is contained in:
parent
1f10a39d31
commit
32acc4a72b
|
@ -665,6 +665,7 @@ class IntegerField(Field):
|
||||||
'max_string_length': _('String value too large.')
|
'max_string_length': _('String value too large.')
|
||||||
}
|
}
|
||||||
MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
|
MAX_STRING_LENGTH = 1000 # Guard against malicious string inputs.
|
||||||
|
re_decimal = re.compile(r'\.0*\s*$') # allow e.g. '1.0' as an int, but not '1.2'
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.max_value = kwargs.pop('max_value', None)
|
self.max_value = kwargs.pop('max_value', None)
|
||||||
|
@ -682,7 +683,7 @@ class IntegerField(Field):
|
||||||
self.fail('max_string_length')
|
self.fail('max_string_length')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = int(re.compile(r'\.0*\s*$').sub('', str(data)))
|
data = int(self.re_decimal.sub('', str(data)))
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
self.fail('invalid')
|
self.fail('invalid')
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in New Issue
Block a user