parent
041aa61508
commit
eb276df876
@ -74,6 +74,8 @@ def _parse_search_term(s):
|
||||
term = s
|
||||
else:
|
||||
term = split[1]
|
||||
elif not split:
|
||||
raise ValueError("Empty search term!")
|
||||
else:
|
||||
engine = None
|
||||
term = s
|
||||
@ -253,8 +255,12 @@ def is_url(urlstr):
|
||||
if not autosearch:
|
||||
# no autosearch, so everything is a URL unless it has an explicit
|
||||
# search engine.
|
||||
engine, _term = _parse_search_term(urlstr)
|
||||
return engine is None
|
||||
try:
|
||||
engine, _term = _parse_search_term(urlstr)
|
||||
except ValueError:
|
||||
return False
|
||||
else:
|
||||
return engine is None
|
||||
|
||||
if not qurl_userinput.isValid():
|
||||
# This will also catch URLs containing spaces.
|
||||
|
@ -268,6 +268,12 @@ def test_get_search_url(urlutils_config_stub, url, host, query):
|
||||
assert url.query() == query
|
||||
|
||||
|
||||
@pytest.mark.parametrize('url', ['\n', ' ', '\n '])
|
||||
def test_get_search_url_invalid(urlutils_config_stub, url):
|
||||
with pytest.raises(ValueError):
|
||||
urlutils._get_search_url(url)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('is_url, is_url_no_autosearch, uses_dns, url', [
|
||||
# Normal hosts
|
||||
(True, True, False, 'http://foobar'),
|
||||
@ -288,7 +294,7 @@ def test_get_search_url(urlutils_config_stub, url, host, query):
|
||||
# _has_explicit_scheme False, special_url True
|
||||
(True, True, False, 'qute::foo'),
|
||||
# Invalid URLs
|
||||
(False, True, False, ''),
|
||||
(False, False, False, ''),
|
||||
(False, True, False, 'http:foo:0'),
|
||||
# Not URLs
|
||||
(False, True, False, 'foo bar'), # no DNS because of space
|
||||
|
Loading…
Reference in New Issue
Block a user