From d4ffcaf1b103f069ad167e0ec663b10c18cc794d Mon Sep 17 00:00:00 2001 From: niphlod Date: Wed, 30 Dec 2015 16:38:43 +0100 Subject: [PATCH] fixes #1044 This shouldn't have took that much to solve. Really sorry for the delay --- gluon/tests/test_validators.py | 3 +++ gluon/validators.py | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gluon/tests/test_validators.py b/gluon/tests/test_validators.py index 0935cfe2..8a18bd10 100644 --- a/gluon/tests/test_validators.py +++ b/gluon/tests/test_validators.py @@ -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): diff --git a/gluon/validators.py b/gluon/validators.py index d5b41442..1ca9ee49 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -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))