From 312daca2b0485626c67257b534ddc9c323c038e4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 2 Feb 2016 06:38:48 +0100 Subject: [PATCH] fuzzy_url: Raise InvalidUrlError on empty URLs. Before we raised QtValueError (via qtutils.ensure_valid), but maybe there are more callers out there which call fuzzy_url with an empty input - and it makes more sense to raise InvalidUrlError which gets displayed to the user than raising QtValueError which is more like an assertion. --- CHANGELOG.asciidoc | 1 + qutebrowser/utils/urlutils.py | 3 ++- tests/unit/utils/test_urlutils.py | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index ffbfc971f..25b897aa9 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -43,6 +43,7 @@ Fixed the tab it belongs to. - Fixed crash when downloading a file without any path information (e.g a magnet link). +- Fixed crashes when opening an empty URL (e.g. via pasting). v0.5.1 ------ diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index 2406ed43a..e70a09f2d 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -172,6 +172,7 @@ def fuzzy_url(urlstr, cwd=None, relative=False, do_search=True): """ urlstr = urlstr.strip() expanded = os.path.expanduser(urlstr) + if os.path.isabs(expanded): path = expanded elif relative and cwd: @@ -199,7 +200,7 @@ def fuzzy_url(urlstr, cwd=None, relative=False, do_search=True): url = qurl_from_user_input(urlstr) log.url.debug("Converting fuzzy term {} to URL -> {}".format( urlstr, url.toDisplayString())) - if do_search and config.get('general', 'auto-search'): + if do_search and config.get('general', 'auto-search') and urlstr: qtutils.ensure_valid(url) else: if not url.isValid(): diff --git a/tests/unit/utils/test_urlutils.py b/tests/unit/utils/test_urlutils.py index 707edd704..84936be4f 100644 --- a/tests/unit/utils/test_urlutils.py +++ b/tests/unit/utils/test_urlutils.py @@ -233,6 +233,11 @@ class TestFuzzyUrl: with pytest.raises(exception): urlutils.fuzzy_url('foo', do_search=do_search) + @pytest.mark.parametrize('url', ['', ' ']) + def test_empty(self, url): + with pytest.raises(urlutils.InvalidUrlError): + urlutils.fuzzy_url(url, do_search=True) + @pytest.mark.parametrize('url, special', [ ('file:///tmp/foo', True),