diff options
author | Cqoicebordel <Cqoicebordel@users.noreply.github.com> | 2015-06-15 20:34:02 +0200 |
---|---|---|
committer | Cqoicebordel <Cqoicebordel@users.noreply.github.com> | 2015-06-15 20:34:02 +0200 |
commit | e93f5314d745ca389858fdf53f355d8c28928507 (patch) | |
tree | 046e03a97d3ab9daa1425a59ee5083ac39d7f23f /searx/plugins/tracker_url_remover.py | |
parent | 617495cca8b2799945be2c2b042dcc7ce905741a (diff) | |
download | searxng-e93f5314d745ca389858fdf53f355d8c28928507.tar.gz searxng-e93f5314d745ca389858fdf53f355d8c28928507.zip |
A bit of cleanup of the code
- regexes in a array
- regexes applied only on the last part of the url
Diffstat (limited to 'searx/plugins/tracker_url_remover.py')
-rw-r--r-- | searx/plugins/tracker_url_remover.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/searx/plugins/tracker_url_remover.py b/searx/plugins/tracker_url_remover.py index c8459548f..f6ecc2126 100644 --- a/searx/plugins/tracker_url_remover.py +++ b/searx/plugins/tracker_url_remover.py @@ -18,10 +18,9 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >. from flask.ext.babel import gettext import re -re1 = re.compile(r'utm_[^&]+&?') -re2 = re.compile(r'(wkey|wemail)[^&]+&?') -re3 = re.compile(r'&$') -re4 = re.compile(r'^\?$') +regexes = {re.compile(r'utm_[^&]+&?'), + re.compile(r'(wkey|wemail)[^&]+&?'), + re.compile(r'&$')} name = gettext('Tracker URL remover') description = gettext('Remove trackers arguments from the returned URL') @@ -29,12 +28,17 @@ default_on = True def on_result(request, ctx): - url = ctx['result']['url'] + splited_url = ctx['result']['url'].split('?') - url = re1.sub('', url) - url = re2.sub('', url) - url = re3.sub('', url) - url = re4.sub('', url) + if len(splited_url) is not 2: + return True + + for reg in regexes: + splited_url[1] = reg.sub('', splited_url[1]) + + if splited_url[1] == "": + ctx['result']['url'] = splited_url[0] + else: + ctx['result']['url'] = splited_url[0] + '?' + splited_url[1] - ctx['result']['url'] = url return True |