Merge branch 'nanjekyejoannah-issue#1516'

This commit is contained in:
Florian Bruhin 2016-09-06 18:21:34 +02:00
commit 29715ae7a7
6 changed files with 45 additions and 6 deletions

View File

@ -41,6 +41,8 @@ Added
- New `:click-element` command to fake a click on a element. - 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-filter` command to change console log filtering on-the-fly.
- New `:debug-log-level` command to change the console loglevel 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 Changed
~~~~~~~ ~~~~~~~

View File

@ -168,11 +168,11 @@ Contributors, sorted by the number of commits in descending order:
* Jimmy * Jimmy
* Niklas Haas * Niklas Haas
* Alexey "Averrin" Nabrodov * Alexey "Averrin" Nabrodov
* nanjekyejoannah
* avk * avk
* ZDarian * ZDarian
* Milan Svoboda * Milan Svoboda
* John ShaggyTwoDope Jenkins * John ShaggyTwoDope Jenkins
* nanjekyejoannah
* Peter Vilim * Peter Vilim
* Clayton Craft * Clayton Craft
* Oliver Caldwell * Oliver Caldwell

View File

@ -10,6 +10,7 @@
|Setting|Description |Setting|Description
|<<general-ignore-case,ignore-case>>|Whether to find text on a page case-insensitively. |<<general-ignore-case,ignore-case>>|Whether to find text on a page case-insensitively.
|<<general-startpage,startpage>>|The default page(s) to open at the start, separated by commas. |<<general-startpage,startpage>>|The default page(s) to open at the start, separated by commas.
|<<general-yank-ignored-url-parameters,yank-ignored-url-parameters>>|The URL parameters to strip with :yank url, separated by commas.
|<<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. |<<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.
|<<general-auto-search,auto-search>>|Whether to start a search when something else than a URL is entered. |<<general-auto-search,auto-search>>|Whether to start a search when something else than a URL is entered.
|<<general-auto-save-config,auto-save-config>>|Whether to save the config automatically on quit. |<<general-auto-save-config,auto-save-config>>|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]+ 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]] [[general-default-page]]
=== default-page === default-page
The page to open if :open -t/-b/-w is used without URL. Use `about:blank` for a blank page. The page to open if :open -t/-b/-w is used without URL. Use `about:blank` for a blank page.

View File

@ -25,7 +25,7 @@ import shlex
import functools import functools
from PyQt5.QtWidgets import QApplication, QTabBar 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.QtGui import QKeyEvent
from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog from PyQt5.QtPrintSupport import QPrintDialog, QPrintPreviewDialog
try: try:
@ -673,6 +673,20 @@ class CommandDispatcher:
"Numeric argument is too large for internal int " "Numeric argument is too large for internal int "
"representation.") "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.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('what', choices=['selection', 'url', 'pretty-url', @cmdutils.argument('what', choices=['selection', 'url', 'pretty-url',
'title', 'domain']) 'title', 'domain'])
@ -699,10 +713,7 @@ class CommandDispatcher:
self._current_url().host(), self._current_url().host(),
':' + str(port) if port > -1 else '') ':' + str(port) if port > -1 else '')
elif what in ['url', 'pretty-url']: elif what in ['url', 'pretty-url']:
flags = QUrl.RemovePassword s = self._yank_url(what)
if what != 'pretty-url':
flags |= QUrl.FullyEncoded
s = self._current_url().toString(flags)
what = 'URL' # For printing what = 'URL' # For printing
elif what == 'selection': elif what == 'selection':
caret = self._current_widget().caret caret = self._current_widget().caret

View File

@ -139,6 +139,13 @@ def data(readonly=False):
SettingValue(typ.List(typ.String()), 'https://duckduckgo.com'), SettingValue(typ.List(typ.String()), 'https://duckduckgo.com'),
"The default page(s) to open at the start, separated by commas."), "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 URL parameters to strip with :yank url, separated by "
"commas."),
('default-page', ('default-page',
SettingValue(typ.FuzzyUrl(), '${startpage}'), SettingValue(typ.FuzzyUrl(), '${startpage}'),
"The page to open if :open -t/-b/-w is used without URL. Use " "The page to open if :open -t/-b/-w is used without URL. Use "

View File

@ -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 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" 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 Scenario: Yanking title to clipboard
When I open data/title.html When I open data/title.html
And I wait for regex "Changing title for idx \d to 'Test title'" in the log And I wait for regex "Changing title for idx \d to 'Test title'" in the log