From d3e19ec8fcb49ea42937eb24c1b9576408477ca9 Mon Sep 17 00:00:00 2001 From: nanjekyejoannah Date: Wed, 24 Aug 2016 16:17:09 +0300 Subject: [PATCH 1/3] Add general -> yank-ignored-url-parameters --- qutebrowser/browser/commands.py | 10 ++++++++-- qutebrowser/config/configdata.py | 6 ++++++ tests/end2end/features/yankpaste.feature | 12 ++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 046b32ce1..8d6f5ef65 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -25,7 +25,7 @@ import shlex import functools from PyQt5.QtWidgets import QApplication, QTabBar -from PyQt5.QtCore import Qt, QUrl, QEvent +from PyQt5.QtCore import Qt, QUrl, QEvent, QUrlQuery from PyQt5.QtGui import QKeyEvent from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog try: @@ -702,7 +702,13 @@ class CommandDispatcher: flags = QUrl.RemovePassword if what != 'pretty-url': flags |= QUrl.FullyEncoded - s = self._current_url().toString(flags) + url = QUrl(self._current_url()) + url_query = QUrlQuery(url) + for key in dict(url_query.queryItems()): + if key in config.get('general', 'yank-ignored-url-parameters'): + url_query.removeQueryItem(key) + url.setQuery(url_query) + s = url.toString(flags) what = 'URL' # For printing elif what == 'selection': caret = self._current_widget().caret diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 533b354f8..d54e3a981 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -139,6 +139,12 @@ def data(readonly=False): SettingValue(typ.List(typ.String()), 'https://duckduckgo.com'), "The default page(s) to open at the start, separated by commas."), + ('yank-ignored-url-parameters', + SettingValue(typ.List(typ.String()), 'ref,utm_source,' + 'utm_medium,utm_campaign,utm_term,utm_content'), + "The default parameters to strip on yank," + " separated by commas."), + ('default-page', SettingValue(typ.FuzzyUrl(), '${startpage}'), "The page to open if :open -t/-b/-w is used without URL. Use " diff --git a/tests/end2end/features/yankpaste.feature b/tests/end2end/features/yankpaste.feature index e5f783e4f..10ed825a9 100644 --- a/tests/end2end/features/yankpaste.feature +++ b/tests/end2end/features/yankpaste.feature @@ -20,6 +20,18 @@ Feature: Yanking and pasting. Then the message "Yanked URL to primary selection: http://localhost:(port)/data/title.html" should be shown And the primary selection should contain "http://localhost:(port)/data/title.html" + Scenario: Yanking URLs with ref and UTM parameters + When I open data/title.html?utm_source=kikolani&utm_medium=320banner&utm_campaign=bpp&ref=facebook + And I run :yank + Then the message "Yanked URL to clipboard: http://localhost:(port)/data/title.html" should be shown + And the clipboard should contain "http://localhost:(port)/data/title.html" + + Scenario: Yanking URLs with ref and UTM parameters and some other parameters + When I open data/title.html?stype=models&utm_source=kikolani&utm_medium=320banner&utm_campaign=bpp&ref=facebook + And I run :yank + Then the message "Yanked URL to clipboard: http://localhost:(port)/data/title.html?stype=models" should be shown + And the clipboard should contain "http://localhost:(port)/data/title.html?stype=models" + Scenario: Yanking title to clipboard When I open data/title.html And I wait for regex "Changing title for idx \d to 'Test title'" in the log From 7c4548ece1827e0cd5fa9b8acc83c33eb6c01e26 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 6 Sep 2016 18:16:32 +0200 Subject: [PATCH 2/3] Split off _yank_url from :yank --- qutebrowser/browser/commands.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index 8d6f5ef65..6a0232cfb 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -673,6 +673,20 @@ class CommandDispatcher: "Numeric argument is too large for internal int " "representation.") + def _yank_url(self, what): + """Helper method for yank() to get the URL to copy.""" + assert what in ['url', 'pretty-url'], what + flags = QUrl.RemovePassword + if what != 'pretty-url': + flags |= QUrl.FullyEncoded + url = QUrl(self._current_url()) + url_query = QUrlQuery(url) + for key in dict(url_query.queryItems()): + if key in config.get('general', 'yank-ignored-url-parameters'): + url_query.removeQueryItem(key) + url.setQuery(url_query) + return url.toString(flags) + @cmdutils.register(instance='command-dispatcher', scope='window') @cmdutils.argument('what', choices=['selection', 'url', 'pretty-url', 'title', 'domain']) @@ -699,16 +713,7 @@ class CommandDispatcher: self._current_url().host(), ':' + str(port) if port > -1 else '') elif what in ['url', 'pretty-url']: - flags = QUrl.RemovePassword - if what != 'pretty-url': - flags |= QUrl.FullyEncoded - url = QUrl(self._current_url()) - url_query = QUrlQuery(url) - for key in dict(url_query.queryItems()): - if key in config.get('general', 'yank-ignored-url-parameters'): - url_query.removeQueryItem(key) - url.setQuery(url_query) - s = url.toString(flags) + s = self._yank_url(what) what = 'URL' # For printing elif what == 'selection': caret = self._current_widget().caret From b65440e7e34f53506b76168b1666d7c9754b0d9c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 6 Sep 2016 18:17:55 +0200 Subject: [PATCH 3/3] Update docs --- CHANGELOG.asciidoc | 2 ++ README.asciidoc | 2 +- doc/help/settings.asciidoc | 7 +++++++ qutebrowser/config/configdata.py | 9 +++++---- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 5dfaa0086..887e4f604 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -41,6 +41,8 @@ Added - New `:click-element` command to fake a click on a element. - New `:debug-log-filter` command to change console log filtering on-the-fly. - New `:debug-log-level` command to change the console loglevel on-the-fly. +- New `general -> yank-ignored-url-parameters` option to configure which URL + parameters (like `utm_source` etc.) to strip off when yanking an URL. Changed ~~~~~~~ diff --git a/README.asciidoc b/README.asciidoc index 9aa59705e..53796e412 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -168,11 +168,11 @@ Contributors, sorted by the number of commits in descending order: * Jimmy * Niklas Haas * Alexey "Averrin" Nabrodov +* nanjekyejoannah * avk * ZDarian * Milan Svoboda * John ShaggyTwoDope Jenkins -* nanjekyejoannah * Peter Vilim * Clayton Craft * Oliver Caldwell diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 6f4d58868..6c430ae49 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -10,6 +10,7 @@ |Setting|Description |<>|Whether to find text on a page case-insensitively. |<>|The default page(s) to open at the start, separated by commas. +|<>|The URL parameters to strip with :yank url, separated by commas. |<>|The page to open if :open -t/-b/-w is used without URL. Use `about:blank` for a blank page. |<>|Whether to start a search when something else than a URL is entered. |<>|Whether to save the config automatically on quit. @@ -309,6 +310,12 @@ The default page(s) to open at the start, separated by commas. Default: +pass:[https://duckduckgo.com]+ +[[general-yank-ignored-url-parameters]] +=== yank-ignored-url-parameters +The URL parameters to strip with :yank url, separated by commas. + +Default: +pass:[ref,utm_source,utm_medium,utm_campaign,utm_term,utm_content]+ + [[general-default-page]] === default-page The page to open if :open -t/-b/-w is used without URL. Use `about:blank` for a blank page. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index d54e3a981..b5054d75c 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -140,10 +140,11 @@ def data(readonly=False): "The default page(s) to open at the start, separated by commas."), ('yank-ignored-url-parameters', - SettingValue(typ.List(typ.String()), 'ref,utm_source,' - 'utm_medium,utm_campaign,utm_term,utm_content'), - "The default parameters to strip on yank," - " separated by commas."), + SettingValue(typ.List(typ.String()), + 'ref,utm_source,utm_medium,utm_campaign,utm_term,' + 'utm_content'), + "The URL parameters to strip with :yank url, separated by " + "commas."), ('default-page', SettingValue(typ.FuzzyUrl(), '${startpage}'),