diff options
author | Thorsten Wißmann <edu@thorsten-wissmann.de> | 2020-03-27 09:01:32 +0100 |
---|---|---|
committer | Thorsten Wißmann <edu@thorsten-wissmann.de> | 2020-04-04 11:02:23 +0200 |
commit | f93d5380def6127a364c3b6a165d764546ed7d14 (patch) | |
tree | 492834e862db87782915373121f6dda033bdc462 /qutebrowser/utils/urlutils.py | |
parent | 60535cf72b9978ca40cba1f3237d3c206aac0c4e (diff) | |
download | qutebrowser-f93d5380def6127a364c3b6a165d764546ed7d14.tar.gz qutebrowser-f93d5380def6127a364c3b6a165d764546ed7d14.zip |
Only quote search engine terms if requested
In the search engine url replacement, only quote the search term if the
search engine format explicitly requests this:
- The placeholder {} quotes all characters except '/' like before of
#4434. This seems to be the default for other browsers' search
engines and to be supported by most websites. For example,
https://en.wikipedia.org/wiki/AC/DC leads to the wikipedia article
of AC/DC.
- New placeholders allow to specify how the search term shall be
quoted: {unquoted} inserts the plain search term, {semiquoted}
behaves like {} and {quoted} inserts the quoted search term. For
example, with
c.url.searchengines['jpc'] = 'https://www.jpc.de/s/{quoted}'
the command "jpc AC/DC" redirects to https://www.jpc.de/s/AC%2FDC
given results for "AC/DC". Here, the placeholder {quoted} is indeed
necessary (as of March 2020), since https://www.jpc.de/s/AC/DC only
searches for "AC".
This addresses the issue #1772 and partially reverts #4434 (making the
there introduced behaviour configurable).
Diffstat (limited to 'qutebrowser/utils/urlutils.py')
-rw-r--r-- | qutebrowser/utils/urlutils.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/qutebrowser/utils/urlutils.py b/qutebrowser/utils/urlutils.py index b0013c195..9212405b3 100644 --- a/qutebrowser/utils/urlutils.py +++ b/qutebrowser/utils/urlutils.py @@ -116,8 +116,14 @@ def _get_search_url(txt: str) -> QUrl: engine = 'DEFAULT' if term: template = config.val.url.searchengines[engine] + semiquoted_term = urllib.parse.quote(term) quoted_term = urllib.parse.quote(term, safe='') - url = qurl_from_user_input(template.format(quoted_term)) + format_keys = { + 'unquoted': term, + 'quoted': quoted_term, + 'semiquoted': semiquoted_term, + } + url = qurl_from_user_input(template.format(semiquoted_term, **format_keys)) else: url = qurl_from_user_input(config.val.url.searchengines[engine]) url.setPath(None) # type: ignore |