diff options
author | Martin Fischer <martin@push-f.com> | 2022-01-13 19:39:18 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-01-13 19:43:49 +0100 |
commit | d9709df7406a38b886b95add6f7117a9be2e1440 (patch) | |
tree | b5e60470722233a143bc08a69481f38eee12164e /searx/preferences.py | |
parent | 687bdef4108f9d76e5b4dc3d847479ba257626c8 (diff) | |
download | searxng-d9709df7406a38b886b95add6f7117a9be2e1440.tar.gz searxng-d9709df7406a38b886b95add6f7117a9be2e1440.zip |
[fix] make BooleanChoices only set cookies that vary from the default
The bug was inadvertently introduced by the refactor in
180d4d068b4c629ab99876b55046f98455b88149.
Fixes #746.
Diffstat (limited to 'searx/preferences.py')
-rw-r--r-- | searx/preferences.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/searx/preferences.py b/searx/preferences.py index 223858a5b..570d0901b 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -205,6 +205,7 @@ class BooleanChoices: self.name = name self.choices = choices self.locked = locked + self.default_choices = dict(choices) def transform_form_items(self, items): # pylint: disable=no-self-use @@ -241,8 +242,10 @@ class BooleanChoices: def save(self, resp: flask.Response): """Save cookie in the HTTP reponse obect""" - resp.set_cookie('disabled_{0}'.format(self.name), ','.join(self.disabled), max_age=COOKIE_MAX_AGE) - resp.set_cookie('enabled_{0}'.format(self.name), ','.join(self.enabled), max_age=COOKIE_MAX_AGE) + disabled_changed = (k for k in self.disabled if self.default_choices[k]) + enabled_changed = (k for k in self.enabled if not self.default_choices[k]) + resp.set_cookie('disabled_{0}'.format(self.name), ','.join(disabled_changed), max_age=COOKIE_MAX_AGE) + resp.set_cookie('enabled_{0}'.format(self.name), ','.join(enabled_changed), max_age=COOKIE_MAX_AGE) def get_disabled(self): return self.transform_values(list(self.disabled)) |