diff --git a/qutebrowser/config/configcommands.py b/qutebrowser/config/configcommands.py index 311ee4102..f81c21aac 100644 --- a/qutebrowser/config/configcommands.py +++ b/qutebrowser/config/configcommands.py @@ -59,6 +59,13 @@ class ConfigCommands: raise cmdexc.CommandError("Error while parsing {}: {}" .format(pattern, str(e))) + def _parse_key(self, key): + """Parse a key argument.""" + try: + return keyutils.KeySequence.parse(key) + except keyutils.KeyParseError as e: + raise cmdexc.CommandError(str(e)) + def _print_value(self, option, pattern): """Print the value of the given option.""" with self._handle_config_error(): @@ -143,7 +150,7 @@ class ConfigCommands: tabbed_browser.openurl(QUrl('qute://bindings'), newtab=True) return - seq = keyutils.KeySequence.parse(key) + seq = self._parse_key(key) if command is None: if default: @@ -176,7 +183,7 @@ class ConfigCommands: See `:help bindings.commands` for the available modes. """ with self._handle_config_error(): - self._keyconfig.unbind(keyutils.KeySequence.parse(key), mode=mode, + self._keyconfig.unbind(self._parse_key(key), mode=mode, save_yaml=True) @cmdutils.register(instance='config-commands', star_args_optional=True) diff --git a/tests/unit/config/test_configcommands.py b/tests/unit/config/test_configcommands.py index 0e2427c06..a74b446d1 100644 --- a/tests/unit/config/test_configcommands.py +++ b/tests/unit/config/test_configcommands.py @@ -557,12 +557,18 @@ class TestBind: # :bind --default foobar ('bind', ['foobar'], {'default': True}, "Can't find binding 'foobar' in normal mode"), + # :bind nop + ('bind', ['', 'nop'], {}, + "Could not parse '': Got unknown key!"), # :unbind foobar ('unbind', ['foobar'], {}, "Can't find binding 'foobar' in normal mode"), # :unbind --mode=wrongmode x ('unbind', ['x'], {'mode': 'wrongmode'}, 'Invalid mode wrongmode!'), + # :unbind + ('unbind', [''], {}, + "Could not parse '': Got unknown key!"), ]) def test_bind_invalid(self, commands, command, args, kwargs, expected):