Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Set IntegerField class variable for compiled decimal regex, comment f…
…or purpose
  • Loading branch information
Ryan Allen committed Apr 21, 2015
commit 32acc4a72bf62d9790be832504746054d6ef5ce5
3 changes: 2 additions & 1 deletion rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ class IntegerField(Field):
'max_string_length': _('String value too large.')
}
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):
self.max_value = kwargs.pop('max_value', None)
Expand All @@ -682,7 +683,7 @@ def to_internal_value(self, data):
self.fail('max_string_length')

try:
data = int(re.compile(r'\.0*\s*$').sub('', str(data)))
data = int(self.re_decimal.sub('', str(data)))
except (ValueError, TypeError):
self.fail('invalid')
return data
Expand Down