Use parsed_url

This commit is contained in:
Cqoicebordel 2015-06-18 14:27:15 +02:00
parent e93f5314d7
commit 8911233e3e

View file

@ -17,6 +17,7 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
from flask.ext.babel import gettext from flask.ext.babel import gettext
import re import re
from urlparse import urlunparse
regexes = {re.compile(r'utm_[^&]+&?'), regexes = {re.compile(r'utm_[^&]+&?'),
re.compile(r'(wkey|wemail)[^&]+&?'), re.compile(r'(wkey|wemail)[^&]+&?'),
@ -28,17 +29,16 @@ default_on = True
def on_result(request, ctx): def on_result(request, ctx):
splited_url = ctx['result']['url'].split('?') query = ctx['result']['parsed_url'].query
if len(splited_url) is not 2: if query == "":
return True return True
for reg in regexes: for reg in regexes:
splited_url[1] = reg.sub('', splited_url[1]) query = reg.sub('', query)
if splited_url[1] == "": if query != ctx['result']['parsed_url'].query:
ctx['result']['url'] = splited_url[0] ctx['result']['parsed_url'] = ctx['result']['parsed_url']._replace(query=query)
else: ctx['result']['url'] = urlunparse(ctx['result']['parsed_url'])
ctx['result']['url'] = splited_url[0] + '?' + splited_url[1]
return True return True