diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index 14855bf03..217e94505 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1654,6 +1654,13 @@ class Key(BaseType): return None try: - return keyutils.KeySequence.parse(value) + seq = keyutils.KeySequence.parse(value) except keyutils.KeyParseError as e: raise configexc.ValidationError(value, str(e)) + + for info in seq: + if Qt.Key_1 <= info.key <= Qt.Key_9 and not info.modifiers: + raise configexc.ValidationError( + value, "Numbers are reserved for counts!") + + return seq diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index c64891e5a..074a54f23 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -2061,13 +2061,16 @@ class TestKey: @pytest.mark.parametrize('val, expected', [ ('gC', keyutils.KeySequence.parse('gC')), ('', keyutils.KeySequence.parse('')), + ('', keyutils.KeySequence.parse('')), + ('0', keyutils.KeySequence.parse('0')), ]) def test_to_py_valid(self, klass, val, expected): assert klass().to_py(val) == expected - def test_to_py_invalid(self, klass): + @pytest.mark.parametrize('val', ['\U00010000', '', '1', 'a1']) + def test_to_py_invalid(self, klass, val): with pytest.raises(configexc.ValidationError): - klass().to_py('\U00010000') + klass().to_py(val) @pytest.mark.parametrize('first, second, equal', [