diff --git a/owrx/property/validators.py b/owrx/property/validators.py index 5d474bc..9a9ebfe 100644 --- a/owrx/property/validators.py +++ b/owrx/property/validators.py @@ -84,7 +84,7 @@ class RegexValidator(Validator): self.regex = regex 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 = { diff --git a/test/property/validators/test_regex_validator.py b/test/property/validators/test_regex_validator.py index 1bdfb6c..2151d1b 100644 --- a/test/property/validators/test_regex_validator.py +++ b/test/property/validators/test_regex_validator.py @@ -11,3 +11,7 @@ class RegexValidatorTest(TestCase): def testDoesntMatchRegex(self): validator = RegexValidator(re.compile("abc")) self.assertFalse(validator.isValid("xyz")) + + def testFailsIfValueIsNoString(self): + validator = RegexValidator(re.compile("abc")) + self.assertFalse(validator.isValid(42))