configtypes: Handle max. recursion depth for Regex.

This commit is contained in:
Florian Bruhin 2015-11-04 07:02:23 +01:00
parent 2c7b0d2fb4
commit 702842c977
2 changed files with 5 additions and 1 deletions

View File

@ -60,6 +60,9 @@ def _validate_regex(pattern, flags):
except re.error as e:
raise configexc.ValidationError(
pattern, "must be a valid regex - " + str(e))
except RuntimeError:
raise configexc.ValidationError(
pattern, "must be a valid regex - recursion depth exceeded")
for w in recorded_warnings:
if (issubclass(w.category, DeprecationWarning) and

View File

@ -1149,7 +1149,7 @@ class TestRegex:
def test_validate_valid(self, klass, val):
klass(none_ok=True).validate(val)
@pytest.mark.parametrize('val', [r'(foo|bar))?baz[fis]h', ''])
@pytest.mark.parametrize('val', [r'(foo|bar))?baz[fis]h', '', '(' * 500])
def test_validate_invalid(self, klass, val):
with pytest.raises(configexc.ValidationError):
klass().validate(val)
@ -1225,6 +1225,7 @@ class TestRegexList:
r'(foo|bar),,1337{42}',
r'',
r'(foo|bar),((),1337{42}',
r'(' * 500,
])
def test_validate_invalid(self, klass, val):
with pytest.raises(configexc.ValidationError):