Disallow {foo} in search engine URLs.
This causes an KeyError otherwise when trying to use str.format to insert the search term.
This commit is contained in:
parent
b21b4377a8
commit
b7c3e7b959
@ -1110,8 +1110,15 @@ class SearchEngineUrl(BaseType):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
raise configexc.ValidationError(value, "may not be empty!")
|
raise configexc.ValidationError(value, "may not be empty!")
|
||||||
|
|
||||||
if '{}' not in value:
|
if '{}' not in value:
|
||||||
raise configexc.ValidationError(value, "must contain \"{}\"")
|
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'))
|
url = QUrl(value.replace('{}', 'foobar'))
|
||||||
if not url.isValid():
|
if not url.isValid():
|
||||||
raise configexc.ValidationError(value, "invalid url, {}".format(
|
raise configexc.ValidationError(value, "invalid url, {}".format(
|
||||||
|
@ -1881,6 +1881,11 @@ class TestSearchEngineUrl:
|
|||||||
with pytest.raises(configexc.ValidationError):
|
with pytest.raises(configexc.ValidationError):
|
||||||
self.t.validate(':{}')
|
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):
|
def test_transform_empty(self):
|
||||||
"""Test transform with an empty value."""
|
"""Test transform with an empty value."""
|
||||||
assert self.t.transform('') is None
|
assert self.t.transform('') is None
|
||||||
|
Loading…
Reference in New Issue
Block a user