From e259293f83dc613e82983464ce5f85846bedfeb2 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 3 Jul 2017 12:02:52 +0200 Subject: [PATCH] Always copy config objects If we mutate the value we get from the config, we want to make sure the value in the config always stays the same (especially when it's the default!). --- qutebrowser/config/config.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index cc269491f..6a1b1024c 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -412,7 +412,10 @@ class Config(QObject): If mutable=True is set, watch the returned object for mutations. """ opt = self.get_opt(name) - obj = self._values.get(name, opt.default) + # We always return a copy of the value stored internally, so the + # internal value can never be changed by mutating the object returned. + obj = copy.deepcopy(self._values.get(name, opt.default)) + # Then we watch the returned object for changes. if isinstance(obj, (dict, list)): if mutable: self._mutables.append((name, copy.deepcopy(obj), obj))