allow regexes only on strings
This commit is contained in:
parent
a880b1f6f9
commit
d126c3acef
@ -84,7 +84,7 @@ class RegexValidator(Validator):
|
|||||||
self.regex = regex
|
self.regex = regex
|
||||||
|
|
||||||
def isValid(self, value):
|
def isValid(self, value):
|
||||||
return self.regex.match(value) is not None
|
return isinstance(value, str) and self.regex.match(value) is not None
|
||||||
|
|
||||||
|
|
||||||
validator_types = {
|
validator_types = {
|
||||||
|
@ -11,3 +11,7 @@ class RegexValidatorTest(TestCase):
|
|||||||
def testDoesntMatchRegex(self):
|
def testDoesntMatchRegex(self):
|
||||||
validator = RegexValidator(re.compile("abc"))
|
validator = RegexValidator(re.compile("abc"))
|
||||||
self.assertFalse(validator.isValid("xyz"))
|
self.assertFalse(validator.isValid("xyz"))
|
||||||
|
|
||||||
|
def testFailsIfValueIsNoString(self):
|
||||||
|
validator = RegexValidator(re.compile("abc"))
|
||||||
|
self.assertFalse(validator.isValid(42))
|
||||||
|
Loading…
Reference in New Issue
Block a user