diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 7be075d2a..932ccd80e 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -86,6 +86,7 @@ Changed - `:tab-move +/-` now wraps around if `tabs -> wrap` is `true`. - When a subprocess (like launched by `:spawn`) fails, its stdout/stderr is now logged to the console. +- A search engine name can now contain any non-space character, like dashes. Deprecated ~~~~~~~~~~ diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 4c189ac3b..c8917efe5 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -62,19 +62,22 @@ def _parse_search_term(s): Return: A (engine, term) tuple, where engine is None for the default engine. """ - m = re.search(r'(^\w+)\s+(.+)($|\s+)', s) - if m: - engine = m.group(1) + s = s.strip() + splitted = s.split(maxsplit=1) + + if len(splitted) == 2: + engine = splitted[0] try: config.get('searchengines', engine) except configexc.NoOptionError: engine = None term = s else: - term = m.group(2).rstrip() + term = splitted[1] else: engine = None term = s + log.url.debug("engine {}, term '{}'".format(engine, term)) return (engine, term) diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index 67f876ed0..98609c1f9 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -98,6 +98,7 @@ def urlutils_config_stub(config_stub, monkeypatch): 'general': {'auto-search': True}, 'searchengines': { 'test': 'http://www.qutebrowser.org/?q={}', + 'test-with-dash': 'http://www.example.org/?q={}', 'DEFAULT': 'http://www.example.com/?q={}', }, } @@ -247,6 +248,8 @@ def test_special_urls(url, special): ('test testfoo ', 'www.qutebrowser.org', 'q=testfoo'), ('!python testfoo', 'www.example.com', 'q=%21python testfoo'), ('blub testfoo', 'www.example.com', 'q=blub testfoo'), + ('stripped ', 'www.example.com', 'q=stripped'), + ('test-with-dash testfoo', 'www.example.org', 'q=testfoo'), ]) def test_get_search_url(urlutils_config_stub, url, host, query): """Test _get_search_url().