From 702842c9772546952c66494cb94e8e47980796c4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 4 Nov 2015 07:02:23 +0100 Subject: [PATCH] configtypes: Handle max. recursion depth for Regex. --- qutebrowser/config/configtypes.py | 3 +++ tests/unit/config/test_configtypes.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 9d00aa5fc..4066c4cbf 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -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 diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index b7ddcedb4..7c8bf8d56 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -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):