From 8f44014627ff26019c0ffc01f77394f56dfb7db1 Mon Sep 17 00:00:00 2001 From: rachmadani haryono Date: Wed, 17 Jul 2019 15:42:40 +0800 Subject: [PATCH] [fix] preference query parameter decoding (#1599) Fix issue #1598 --- searx/preferences.py | 5 ++++- tests/unit/test_preferences.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/searx/preferences.py b/searx/preferences.py index acaa67f66..30a4252b0 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -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(): diff --git a/tests/unit/test_preferences.py b/tests/unit/test_preferences.py index 885c515e2..61ac0e8e4 100644 --- a/tests/unit/test_preferences.py +++ b/tests/unit/test_preferences.py @@ -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']})