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