From 994181212734cacdfa6e4d7cb35402881282bf4f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 12 Mar 2018 08:00:56 +0100 Subject: [PATCH] Normalize keys read from the config This makes sure the internal bindings.commands object only contains normalized key sequences. Fixes #3699 --- qutebrowser/config/configtypes.py | 3 +++ tests/unit/config/test_config.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index e84d55075..e85d153b9 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1650,6 +1650,9 @@ class Key(BaseType): """A name of a key.""" + def from_obj(self, value): + return str(keyutils.KeySequence.parse(value)) + def to_py(self, value): self._basic_py_validation(value, str) if not value: diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index 9104c0f53..e1ef7ef94 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -339,6 +339,24 @@ class TestKeyConfig: key_config_stub.unbind(seq) assert key_config_stub.get_command(seq, mode='normal') is None + def test_unbind_old_syntax(self, yaml_config_stub, key_config_stub, + config_stub): + """Test unbinding bindings added before the keybinding refactoring. + + We used to normalize keys differently, so we can have in the + config. + + See https://github.com/qutebrowser/qutebrowser/issues/3699 + """ + bindings = {'normal': {'': 'nop'}} + yaml_config_stub.set_obj('bindings.commands', bindings) + config_stub.read_yaml() + + key_config_stub.unbind(keyutils.KeySequence.parse(''), + save_yaml=True) + + assert config.instance.get_obj('bindings.commands') == {'normal': {}} + def test_empty_command(self, key_config_stub): """Try binding a key to an empty command.""" message = "Can't add binding 'x' with empty command in normal mode"