diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 23909b9c1..d3f0b0d8d 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1110,8 +1110,15 @@ class SearchEngineUrl(BaseType): return else: raise configexc.ValidationError(value, "may not be empty!") + if '{}' not in value: raise configexc.ValidationError(value, "must contain \"{}\"") + try: + value.format("") + except KeyError: + raise configexc.ValidationError( + value, "may not contain {...} (use {{ and }} for literal {/})") + url = QUrl(value.replace('{}', 'foobar')) if not url.isValid(): raise configexc.ValidationError(value, "invalid url, {}".format( diff --git a/tests/config/test_configtypes.py b/tests/config/test_configtypes.py index 6b6a08594..edb0bb8cb 100644 --- a/tests/config/test_configtypes.py +++ b/tests/config/test_configtypes.py @@ -1881,6 +1881,11 @@ class TestSearchEngineUrl: with pytest.raises(configexc.ValidationError): self.t.validate(':{}') + def test_validate_format_string(self): + """Test validate with a {foo} format string.""" + with pytest.raises(configexc.ValidationError): + self.t.validate('foo{bar}baz{}') + def test_transform_empty(self): """Test transform with an empty value.""" assert self.t.transform('') is None