1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 04:01:40 +01:00

[fix] preference query parameter decoding (#1599)

Fix issue #1598
This commit is contained in:
rachmadani haryono 2019-07-17 15:42:40 +08:00 committed by Alexandre Flament
parent 582f3bfcbc
commit 8f44014627
2 changed files with 24 additions and 1 deletions

View File

@ -292,7 +292,10 @@ class Preferences(object):
def parse_encoded_data(self, input_data):
decoded_data = decompress(urlsafe_b64decode(input_data.encode('utf-8')))
self.parse_dict({x: y[0] for x, y in parse_qs(unicode(decoded_data)).items()})
dict_data = {}
for x, y in parse_qs(decoded_data).items():
dict_data[x.decode('utf8')] = y[0].decode('utf8')
self.parse_dict(dict_data)
def parse_dict(self, input_data):
for user_setting_name, user_setting in input_data.items():

View File

@ -122,3 +122,23 @@ class TestSettings(SearxTestCase):
plugin3 = PluginStub('plugin3', True)
setting = PluginsSetting('name', choices=[plugin1, plugin2, plugin3])
self.assertEquals(setting.get_enabled(), set(['plugin1', 'plugin3']))
class TestPreferences(SearxTestCase):
def test_encode(self):
from searx.preferences import Preferences
pref = Preferences(['oscar'], ['general'], {}, [])
url_params = 'eJx1VMmO2zAM_Zr6YrTocujJh6JF0QEKzKAz7VVgJNohLIseUU7ivy-VcWy5yyGOTVGP73GLKJNPYjiYgGeT4NB8BS9YOSY' \
'TUdifMDYM-vmGY1d5CN0EHTYOK88W_PXNkcDBozOjnzoK0vyi4bWnHs2RU4-zvHr_-RF9a-5Cy3GARByy7X7EkKMoBeMp9CuPQ-SzYMx' \
'8Vr9P1qKI-XJ_p1fOkRJWNCgVM0a-zAttmBJbHkaPSZlNts-_jiuBFgUh2mPztkpHHLBhsRArDHvm356eHh5vATS0Mqagr0ZsZO_V8hT' \
'B9srt54_v6jewJugqL4Nn_hYSdhxnI-jRpi05GDQCStOT7UGVmJY8ZnltRKyF23SGiLWjqNcygKGkpyeGZIywJfD1gI5AjRTAmBM55Aw' \
'Q0Tn626lj7jzWo4e5hnEsIlprX6dTgdBRpyRBFKTDgBF8AasVyT4gvSTEoXRpXWRyG3CYQYld65I_V6lboILTMAlZY65_ejRDcHgp0Tv' \
'EPtGAsqTiBf3m76g7pP9B84mwjPvuUtASRDei1nDF2ix_JXW91UJkXrPh6RAhznVmKyQl7dwJdMJ6bz1QOmgzYlrEzHDMcEUuo44AgS1' \
'CvkjaOb2Q2AyY5oGDTs_OLXE_c2I5cg9hk3kEJZ0fu4SuktsIA2RhuJwP86AdripThCBeO9uVUejyPGmFSxPrqEYcuWi25zOEXV9tc1m' \
'_KP1nafYtdfv6Q9hKfWmGm9A_3G635UwiVndLGdFCiLWkONk0xUxGLGGweGWTa2nZYZ0fS1YKlE3Uuw8fPl52E5U8HJYbC7sbjXUsrnT' \
'XHXRbELfO-1fGSqskiGnMK7B0dV3t8Lq08pbdtYpuVdoKWA2Yjuyah_vHp2rZWjo0zXL8Gw8DTj0='
pref.parse_encoded_data(url_params)
self.assertEqual(
vars(pref.key_value_settings['categories']),
{'value': ['general'], 'choices': ['general', 'none']})