From 089131c79dbc069c5c5ce30f70b4392d1bd7d80a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 9 Jun 2016 17:43:33 +0200 Subject: [PATCH] Improve error message when clicking invalid link --- qutebrowser/browser/webpage.py | 7 +++---- tests/end2end/data/invalid_link.html | 11 +++++++++++ tests/end2end/features/hints.feature | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tests/end2end/data/invalid_link.html diff --git a/qutebrowser/browser/webpage.py b/qutebrowser/browser/webpage.py index 6b01b8a29..21c8a4ea5 100644 --- a/qutebrowser/browser/webpage.py +++ b/qutebrowser/browser/webpage.py @@ -33,7 +33,7 @@ from qutebrowser.config import config from qutebrowser.browser import http, tabhistory, pdfjs from qutebrowser.browser.network import networkmanager from qutebrowser.utils import (message, usertypes, log, jinja, qtutils, utils, - objreg, debug) + objreg, debug, urlutils) class BrowserPage(QWebPage): @@ -570,9 +570,8 @@ class BrowserPage(QWebPage): if typ != QWebPage.NavigationTypeLinkClicked: return True if not url.isValid(): - message.error(self._win_id, "Invalid link {} clicked!".format( - urlstr)) - log.webview.debug(url.errorString()) + msg = urlutils.get_errstring(url, "Invalid link clicked") + message.error(self._win_id, msg) self.open_target = usertypes.ClickTarget.normal return False tabbed_browser = objreg.get('tabbed-browser', scope='window', diff --git a/tests/end2end/data/invalid_link.html b/tests/end2end/data/invalid_link.html new file mode 100644 index 000000000..f4e572b16 --- /dev/null +++ b/tests/end2end/data/invalid_link.html @@ -0,0 +1,11 @@ + + + + + + Invalid link + + + I'm broken + + diff --git a/tests/end2end/features/hints.feature b/tests/end2end/features/hints.feature index 274804744..5d7329fde 100644 --- a/tests/end2end/features/hints.feature +++ b/tests/end2end/features/hints.feature @@ -113,6 +113,12 @@ Feature: Using hints And I run :follow-hint a Then the message "http://localhost:(port)/data/hello.txt" should be shown + Scenario: Clicking an invalid link + When I open data/invalid_link.html + And I run :hint all + And I run :follow-hint a + Then the error "Invalid link clicked - *" should be shown + ### iframes Scenario: Using :follow-hint inside an iframe