Skip to content

Commit

Permalink
Merge pull request #2853 from ryangallen/master
Browse files Browse the repository at this point in the history
Set IntegerField class variable for compiled decimal regex, comment for ...
  • Loading branch information
tomchristie committed Apr 21, 2015
2 parents 605369e + 32acc4a commit 0ca1145
Showing 1 changed file with 2 additions and 1 deletion.
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

0 comments on commit 0ca1145

Please sign in to comment.