Skip to content

Commit

Permalink
Fixed potential decode error in text field
Browse files Browse the repository at this point in the history
  • Loading branch information
leahfitch committed Nov 4, 2014
1 parent 5c91034 commit 3dd7d63
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cellardoor/model/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ def _validate(self, value):
if not isinstance(value, basestring):
raise ValidationError(self.NOT_TEXT)

if not isinstance(value, unicode):
try:
value = value.decode('utf-8')
except UnicodeDecodeError:
raise ValidationError(self.NOT_UTF8)


if self.required and len(value) == 0:
raise ValidationError(self.REQUIRED)

Expand All @@ -130,11 +137,6 @@ def _validate(self, value):
if self.regex is not None and not self.regex.search(value):
raise ValidationError(self.NO_REGEX_MATCH)

try:
value = value.decode('utf-8')
except UnicodeDecodeError:
raise ValidationError(self.NOT_UTF8)

return value


Expand Down

0 comments on commit 3dd7d63

Please sign in to comment.