Merge remote-tracking branch 'origin/pr/3604'
This commit is contained in:
commit
32df91fbae
@ -1472,6 +1472,11 @@ url.incdec_segments:
|
|||||||
desc: URL segments where `:navigate increment/decrement` will search for
|
desc: URL segments where `:navigate increment/decrement` will search for
|
||||||
a number.
|
a number.
|
||||||
|
|
||||||
|
url.open_base_url:
|
||||||
|
type: Bool
|
||||||
|
default: false
|
||||||
|
desc: Open base URL of the searchengine if a searchengine shortcut is invoked without parameters.
|
||||||
|
|
||||||
url.searchengines:
|
url.searchengines:
|
||||||
default:
|
default:
|
||||||
DEFAULT: https://duckduckgo.com/?q={}
|
DEFAULT: https://duckduckgo.com/?q={}
|
||||||
|
@ -102,6 +102,12 @@ def _get_search_url(txt):
|
|||||||
engine = 'DEFAULT'
|
engine = 'DEFAULT'
|
||||||
template = config.val.url.searchengines[engine]
|
template = config.val.url.searchengines[engine]
|
||||||
url = qurl_from_user_input(template.format(urllib.parse.quote(term)))
|
url = qurl_from_user_input(template.format(urllib.parse.quote(term)))
|
||||||
|
|
||||||
|
if config.val.url.open_base_url and term in config.val.url.searchengines:
|
||||||
|
url = qurl_from_user_input(config.val.url.searchengines[term])
|
||||||
|
url.setPath(None)
|
||||||
|
url.setFragment(None)
|
||||||
|
url.setQuery(None)
|
||||||
qtutils.ensure_valid(url)
|
qtutils.ensure_valid(url)
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
@ -278,6 +278,7 @@ def test_special_urls(url, special):
|
|||||||
assert urlutils.is_special_url(QUrl(url)) == special
|
assert urlutils.is_special_url(QUrl(url)) == special
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('open_base_url', [True, False])
|
||||||
@pytest.mark.parametrize('url, host, query', [
|
@pytest.mark.parametrize('url, host, query', [
|
||||||
('testfoo', 'www.example.com', 'q=testfoo'),
|
('testfoo', 'www.example.com', 'q=testfoo'),
|
||||||
('test testfoo', 'www.qutebrowser.org', 'q=testfoo'),
|
('test testfoo', 'www.qutebrowser.org', 'q=testfoo'),
|
||||||
@ -288,7 +289,7 @@ def test_special_urls(url, special):
|
|||||||
('stripped ', 'www.example.com', 'q=stripped'),
|
('stripped ', 'www.example.com', 'q=stripped'),
|
||||||
('test-with-dash testfoo', 'www.example.org', 'q=testfoo'),
|
('test-with-dash testfoo', 'www.example.org', 'q=testfoo'),
|
||||||
])
|
])
|
||||||
def test_get_search_url(url, host, query):
|
def test_get_search_url(config_stub, url, host, query, open_base_url):
|
||||||
"""Test _get_search_url().
|
"""Test _get_search_url().
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -296,11 +297,32 @@ def test_get_search_url(url, host, query):
|
|||||||
host: The expected search machine host.
|
host: The expected search machine host.
|
||||||
query: The expected search query.
|
query: The expected search query.
|
||||||
"""
|
"""
|
||||||
|
config_stub.val.url.open_base_url = open_base_url
|
||||||
url = urlutils._get_search_url(url)
|
url = urlutils._get_search_url(url)
|
||||||
assert url.host() == host
|
assert url.host() == host
|
||||||
assert url.query() == query
|
assert url.query() == query
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('url, host', [
|
||||||
|
('test', 'www.qutebrowser.org'),
|
||||||
|
('test-with-dash', 'www.example.org'),
|
||||||
|
])
|
||||||
|
def test_get_search_url_open_base_url(config_stub, url, host):
|
||||||
|
"""Test _get_search_url() with url.open_base_url_enabled.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url: The "URL" to enter.
|
||||||
|
host: The expected search machine host.
|
||||||
|
query: The expected search query.
|
||||||
|
"""
|
||||||
|
config_stub.val.url.open_base_url = True
|
||||||
|
url = urlutils._get_search_url(url)
|
||||||
|
assert not url.path()
|
||||||
|
assert not url.fragment()
|
||||||
|
assert not url.query()
|
||||||
|
assert url.host() == host
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('url', ['\n', ' ', '\n '])
|
@pytest.mark.parametrize('url', ['\n', ' ', '\n '])
|
||||||
def test_get_search_url_invalid(url):
|
def test_get_search_url_invalid(url):
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
|
Loading…
Reference in New Issue
Block a user