diff options
Diffstat (limited to 'pykwalify/rule.py')
-rw-r--r-- | pykwalify/rule.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/pykwalify/rule.py b/pykwalify/rule.py index 7ac2c9e..a4078ed 100644 --- a/pykwalify/rule.py +++ b/pykwalify/rule.py @@ -340,7 +340,7 @@ class Rule(object): ('matching', 'matching'), ('matching_rule', 'matching_rule'), ('name', 'name'), - ('nullable', 'nullable') + ('nullable', 'nullable'), ('parent', 'parent'), ('pattern', 'pattern'), ('pattern_regexp', 'pattern_regexp'), @@ -1149,7 +1149,7 @@ class Rule(object): v = {} # Check if this is a regex rule. Handle specially - if k.startswith("regex;") or k.startswith("re;"): + if str(k).startswith("regex;") or str(k).startswith("re;"): log.debug(u"Found regex map rule") regex = k.split(";", 1) if len(regex) != 2: @@ -1158,6 +1158,14 @@ class Rule(object): error_key=u"mapping.regex.malformed", path=path, ) + + elif not regex[1].startswith('(') or not regex[1].endswith(')'): + raise RuleError( + msg=u"Regex '{0}' should start and end with parentheses".format(regex[1]), + error_key=u"mapping.regex.missing_parentheses", + path=path, + ) + else: regex = regex[1] try: |