diff options
author | Florian Bruhin <git@the-compiler.org> | 2018-03-12 08:00:56 +0100 |
---|---|---|
committer | Florian Bruhin <git@the-compiler.org> | 2018-03-12 08:03:44 +0100 |
commit | 2e87539b44630843a06d5312bcbd3dd95edcaaf7 (patch) | |
tree | 49947d163d53734cd5924a63250ba5bb38af6a51 | |
parent | 4bff190db950203e443610b7a9e9028d7b5916f8 (diff) | |
download | qutebrowser-2e87539b44630843a06d5312bcbd3dd95edcaaf7.tar.gz qutebrowser-2e87539b44630843a06d5312bcbd3dd95edcaaf7.zip |
Normalize keys read from the config
This makes sure the internal bindings.commands object only contains normalized
key sequences.
Fixes #3699
(cherry picked from commit 994181212734cacdfa6e4d7cb35402881282bf4f)
-rw-r--r-- | qutebrowser/config/configtypes.py | 3 | ||||
-rw-r--r-- | tests/unit/config/test_config.py | 18 |
2 files changed, 21 insertions, 0 deletions
diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 71ff898ea..01bcc5eb0 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 <ctrl+q> in the + config. + + See https://github.com/qutebrowser/qutebrowser/issues/3699 + """ + bindings = {'normal': {'<ctrl+q>': 'nop'}} + yaml_config_stub.set_obj('bindings.commands', bindings) + config_stub.read_yaml() + + key_config_stub.unbind(keyutils.KeySequence.parse('<ctrl+q>'), + 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" |