diff --git a/qutebrowser/config/configfiles.py b/qutebrowser/config/configfiles.py index 82f90db76..05ed23e60 100644 --- a/qutebrowser/config/configfiles.py +++ b/qutebrowser/config/configfiles.py @@ -333,6 +333,9 @@ class ConfigAPI: except urlmatch.ParseError as e: text = "While {} '{}' and parsing pattern".format(action, name) self.errors.append(configexc.ConfigErrorDesc(text, e)) + except keyutils.KeyParseError as e: + text = "While {} '{}' and parsing key".format(action, name) + self.errors.append(configexc.ConfigErrorDesc(text, e)) def finalize(self): """Do work which needs to be done after reading config.py.""" diff --git a/tests/unit/config/test_configfiles.py b/tests/unit/config/test_configfiles.py index c902bb42d..37b565374 100644 --- a/tests/unit/config/test_configfiles.py +++ b/tests/unit/config/test_configfiles.py @@ -29,6 +29,7 @@ from PyQt5.QtCore import QSettings from qutebrowser.config import (config, configfiles, configexc, configdata, configtypes) from qutebrowser.utils import utils, usertypes, urlmatch +from qutebrowser.keyinput import keyutils @pytest.fixture(autouse=True) @@ -699,6 +700,20 @@ class TestConfigPy: message = "'ConfigAPI' object has no attribute 'val'" assert str(error.exception) == message + @pytest.mark.parametrize('line', [ + 'config.bind("", "nop")', + 'config.bind("\U00010000", "nop")', + 'config.unbind("")', + 'config.unbind("\U00010000")', + ]) + def test_invalid_keys(self, confpy, line): + confpy.write(line) + error = confpy.read(error=True) + assert error.text.endswith("and parsing key") + assert isinstance(error.exception, keyutils.KeyParseError) + assert str(error.exception).startswith("Could not parse") + assert str(error.exception).endswith("Got unknown key!") + @pytest.mark.parametrize('line', ["c.foo = 42", "config.set('foo', 42)"]) def test_config_error(self, confpy, line): confpy.write(line)