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.
This commit is contained in:
Florian Bruhin 2016-02-02 06:38:48 +01:00
parent 14042403f6
commit 312daca2b0
3 changed files with 8 additions and 1 deletions

View File

@ -43,6 +43,7 @@ Fixed
the tab it belongs to. the tab it belongs to.
- Fixed crash when downloading a file without any path information (e.g a - Fixed crash when downloading a file without any path information (e.g a
magnet link). magnet link).
- Fixed crashes when opening an empty URL (e.g. via pasting).
v0.5.1 v0.5.1
------ ------

View File

@ -172,6 +172,7 @@ def fuzzy_url(urlstr, cwd=None, relative=False, do_search=True):
""" """
urlstr = urlstr.strip() urlstr = urlstr.strip()
expanded = os.path.expanduser(urlstr) expanded = os.path.expanduser(urlstr)
if os.path.isabs(expanded): if os.path.isabs(expanded):
path = expanded path = expanded
elif relative and cwd: 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) url = qurl_from_user_input(urlstr)
log.url.debug("Converting fuzzy term {} to URL -> {}".format( log.url.debug("Converting fuzzy term {} to URL -> {}".format(
urlstr, url.toDisplayString())) 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) qtutils.ensure_valid(url)
else: else:
if not url.isValid(): if not url.isValid():

View File

@ -233,6 +233,11 @@ class TestFuzzyUrl:
with pytest.raises(exception): with pytest.raises(exception):
urlutils.fuzzy_url('foo', do_search=do_search) 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', [ @pytest.mark.parametrize('url, special', [
('file:///tmp/foo', True), ('file:///tmp/foo', True),