From 203a5dff746917d0dc5d1366eb2fd9e408700483 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 12 May 2017 09:13:19 +0200 Subject: [PATCH] Get rid of webelem.FILTERS There's actually no good reason to filter javascript links as we might want to click them (or copy their URL) just like any other link - this fixes #2404. With that being gone, we don't need FILTERS at all anymore, as we can check for existence of the href attribute in the CSS selector instead. --- CHANGELOG.asciidoc | 1 + qutebrowser/browser/hints.py | 4 +--- qutebrowser/browser/navigate.py | 3 +-- qutebrowser/browser/webelem.py | 18 +++--------------- tests/end2end/data/hints/html/javascript.html | 13 +++++++++++++ tests/end2end/features/hints.feature | 6 ++++++ tests/unit/browser/webkit/test_webkitelem.py | 10 ++-------- 7 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 tests/end2end/data/hints/html/javascript.html diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index bf01a2a17..1dca28d33 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -54,6 +54,7 @@ Changed a restart. - The adblocker now also blocks non-GET requests (e.g. POST) - `:follow-selected` now also works with QtWebEngine +- javascript: links can now be hinted Fixed ~~~~~ diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index a7a5941f9..3cc70f434 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -579,12 +579,10 @@ class HintManager(QObject): if elems is None: message.error("There was an error while getting hint elements") return - - filterfunc = webelem.FILTERS.get(self._context.group, lambda e: True) - elems = [e for e in elems if filterfunc(e)] if not elems: message.error("No elements found.") return + strings = self._hint_strings(elems) log.hints.debug("hints: {}".format(', '.join(strings))) diff --git a/qutebrowser/browser/navigate.py b/qutebrowser/browser/navigate.py index b1ab6f9b1..a3ec15458 100644 --- a/qutebrowser/browser/navigate.py +++ b/qutebrowser/browser/navigate.py @@ -79,8 +79,7 @@ def _find_prevnext(prev, elems): return e # Then check for regular links/buttons. - filterfunc = webelem.FILTERS[webelem.Group.prevnext] - elems = [e for e in elems if e.tag_name() != 'link' and filterfunc(e)] + elems = [e for e in elems if e.tag_name() != 'link'] option = 'prev-regexes' if prev else 'next-regexes' if not elems: return None diff --git a/qutebrowser/browser/webelem.py b/qutebrowser/browser/webelem.py index dce808871..d2e499b83 100644 --- a/qutebrowser/browser/webelem.py +++ b/qutebrowser/browser/webelem.py @@ -22,9 +22,6 @@ Module attributes: Group: Enum for different kinds of groups. SELECTORS: CSS selectors for different groups of elements. - FILTERS: A dictionary of filter functions for the modes. - The filter for "links" filters javascript:-links and a-tags - without "href". """ import collections.abc @@ -45,10 +42,11 @@ SELECTORS = { Group.all: ('a, area, textarea, select, input:not([type=hidden]), button, ' 'frame, iframe, link, [onclick], [onmousedown], [role=link], ' '[role=option], [role=button], img'), - Group.links: 'a, area, link, [role=link]', + Group.links: 'a[href], area[href], link[href], [role=link][href]', Group.images: 'img', Group.url: '[src], [href]', - Group.prevnext: 'a, area, button, link, [role=button]', + Group.prevnext: 'a[href], area[href], button[href], link[href], ' + '[role=button][href]', Group.inputs: ('input[type=text], input[type=email], input[type=url], ' 'input[type=tel], input[type=number], ' 'input[type=password], input[type=search], ' @@ -56,16 +54,6 @@ SELECTORS = { } -def filter_links(elem): - return 'href' in elem and QUrl(elem['href']).scheme() != 'javascript' - - -FILTERS = { - Group.links: filter_links, - Group.prevnext: filter_links, -} - - class Error(Exception): """Base class for WebElement errors.""" diff --git a/tests/end2end/data/hints/html/javascript.html b/tests/end2end/data/hints/html/javascript.html new file mode 100644 index 000000000..89395ff92 --- /dev/null +++ b/tests/end2end/data/hints/html/javascript.html @@ -0,0 +1,13 @@ + + + + + + + + Javascript link + + + Follow me via JS! + + diff --git a/tests/end2end/features/hints.feature b/tests/end2end/features/hints.feature index bdcf9b9d8..a5e073d8a 100644 --- a/tests/end2end/features/hints.feature +++ b/tests/end2end/features/hints.feature @@ -114,6 +114,12 @@ Feature: Using hints And I hint with args "links yank" and follow a Then the clipboard should contain "nobody" + Scenario: Yanking javascript link to clipboard + When I run :debug-set-fake-clipboard + And I open data/hints/html/javascript.html + And I hint with args "links yank" and follow a + Then the clipboard should contain "javascript:window.location.href='/data/hello.txt'" + Scenario: Rapid hinting When I open data/hints/rapid.html in a new tab And I run :tab-only diff --git a/tests/unit/browser/webkit/test_webkitelem.py b/tests/unit/browser/webkit/test_webkitelem.py index 6258508ff..4915c1fba 100644 --- a/tests/unit/browser/webkit/test_webkitelem.py +++ b/tests/unit/browser/webkit/test_webkitelem.py @@ -149,19 +149,17 @@ class SelectionAndFilterTests: ('', [webelem.Group.all, webelem.Group.links, webelem.Group.prevnext, webelem.Group.url]), ('', [webelem.Group.all, + webelem.Group.links, + webelem.Group.prevnext, webelem.Group.url]), ('', [webelem.Group.all]), ('', [webelem.Group.all, webelem.Group.links, webelem.Group.prevnext, webelem.Group.url]), - ('', [webelem.Group.all, - webelem.Group.url]), ('', [webelem.Group.all]), ('', [webelem.Group.all, webelem.Group.links, webelem.Group.prevnext, webelem.Group.url]), - ('', [webelem.Group.all, - webelem.Group.url]), ('