From d3e19ec8fcb49ea42937eb24c1b9576408477ca9 Mon Sep 17 00:00:00 2001 From: nanjekyejoannah Date: Wed, 24 Aug 2016 16:17:09 +0300 Subject: [PATCH] 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