diff options
author | Florian Bruhin <git@the-compiler.org> | 2015-01-09 20:10:39 +0100 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2015-01-09 22:26:35 +0100 |
commit | a4630388346e11cb665ad84cdda13b71bc730cfc (patch) | |
tree | fe9ecbf07a25545024c1f7109527be9dd04e93ab | |
parent | 22761b43732ff7bd04855c2c8b58df767de44622 (diff) | |
download | qutebrowser-a4630388346e11cb665ad84cdda13b71bc730cfc.tar.gz qutebrowser-a4630388346e11cb665ad84cdda13b71bc730cfc.zip |
Make sure QUrl::fromUserInput is valid in is_url.
Fixes #460.
Without this fix, it's possible for URLs to be valid according to is_url, but
not according to QUrl::fromUserInput, e.g. "http:foo:0". This caused an
exception later because fuzzy_url runs qtutils.ensure_valid.
-rw-r--r-- | qutebrowser/test/utils/test_urlutils.py | 1 | ||||
-rw-r--r-- | qutebrowser/utils/urlutils.py | 11 |
2 files changed, 7 insertions, 5 deletions
diff --git a/qutebrowser/test/utils/test_urlutils.py b/qutebrowser/test/utils/test_urlutils.py index 3fbde50a2..79f6ca5b7 100644 --- a/qutebrowser/test/utils/test_urlutils.py +++ b/qutebrowser/test/utils/test_urlutils.py @@ -157,6 +157,7 @@ class IsUrlTests(unittest.TestCase): '1337', 'deadbeef', '31c3', + 'http:foo:0', ) def test_urls(self, configmock): diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index c4468aae3..8bfe1d582 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -205,25 +205,26 @@ def is_url(urlstr): if _has_explicit_scheme(qurl): # URLs with explicit schemes are always URLs log.url.debug("Contains explicit scheme") - return True + url = True elif ' ' in urlstr: # A URL will never contain a space log.url.debug("Contains space -> no URL") - return False + url = False elif is_special_url(qurl): # Special URLs are always URLs, even with autosearch=False log.url.debug("Is an special URL.") - return True + url = True elif autosearch == 'dns': log.url.debug("Checking via DNS") # We want to use qurl_from_user_input here, as the user might enter # "foo.de" and that should be treated as URL here. - return _is_url_dns(qurl_from_user_input(urlstr)) + url = _is_url_dns(qurl_from_user_input(urlstr)) elif autosearch == 'naive': log.url.debug("Checking via naive check") - return _is_url_naive(urlstr) + url = _is_url_naive(urlstr) else: raise ValueError("Invalid autosearch value") + return url and QUrl.fromUserInput(urlstr).isValid() def qurl_from_user_input(urlstr): |