Merge pull request #1154 from niphlod/fix/1044

fixes #1044
This commit is contained in:
mdipierro
2016-01-04 09:41:58 -06:00
2 changed files with 10 additions and 4 deletions
+3
View File
@@ -618,6 +618,9 @@ class TestValidators(unittest.TestCase):
self.assertEqual(rtn, (u'hell', None))
rtn = IS_MATCH('hell', is_unicode=True)(u'hell')
self.assertEqual(rtn, (u'hell', None))
# regr test for #1044
rtn = IS_MATCH('hello')(u'\xff')
self.assertEqual(rtn, (u'\xff', 'Invalid expression'))
def test_IS_EQUAL_TO(self):
+7 -4
View File
@@ -201,12 +201,15 @@ class IS_MATCH(Validator):
def __call__(self, value):
if self.is_unicode:
if isinstance(value,unicode):
match = self.regex.search(value)
else:
if not isinstance(value, unicode):
match = self.regex.search(str(value).decode('utf8'))
else:
match = self.regex.search(value)
else:
match = self.regex.search(str(value))
if not isinstance(value, unicode):
match = self.regex.search(str(value))
else:
match = self.regex.search(value.encode('utf8'))
if match is not None:
return (self.extract and match.group() or value, None)
return (value, translate(self.error_message))