From f7fa31589066ce78430a8b6383b3e259cd74748d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 3 May 2014 00:20:01 +0200 Subject: [PATCH] Better URL detection --- TODO | 1 - qutebrowser/utils/url.py | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index d486e08f7..449ef4750 100644 --- a/TODO +++ b/TODO @@ -46,7 +46,6 @@ catch import errors for PyQt and QtWebKit elem = frame.findFirstElement('*:focus') somehow unfocus elements (hide blinking cursor) when insert mode is left? tabs: some more padding? -localhost:8080 opens searchresults exec command for shell custom stylesheet Alt+N to focus tab N diff --git a/qutebrowser/utils/url.py b/qutebrowser/utils/url.py index 44e78db1f..9fae90094 100644 --- a/qutebrowser/utils/url.py +++ b/qutebrowser/utils/url.py @@ -70,9 +70,18 @@ def _is_url_naive(url): True if the url really is an URL, False otherwise. """ protocols = ['http://', 'https://'] - u = urlstring(url) - return (any(u.startswith(proto) for proto in protocols) or '.' in u or - u == 'localhost') + if isinstance(url, QUrl): + u = url + else: + u = QUrl.fromUserInput(url) + if u.scheme() in protocols: + return True + elif '.' in u.host(): + return True + elif u.host() == 'localhost': + return True + else: + return False def _is_url_dns(url): @@ -127,7 +136,7 @@ def fuzzy_url(url): """ u = qurl(url) urlstr = urlstring(url) - if is_url(u): + if is_url(urlstr): # probably an address logging.debug("url is a fuzzy address") newurl = QUrl.fromUserInput(urlstr)