Disallow numbers in keybindings

Fixes #1966
This commit is contained in:
Florian Bruhin 2018-03-04 23:17:51 +01:00
parent 47525f6a09
commit 4ef5db1bc4
2 changed files with 13 additions and 3 deletions

View File

@ -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

View File

@ -2061,13 +2061,16 @@ class TestKey:
@pytest.mark.parametrize('val, expected', [
('gC', keyutils.KeySequence.parse('gC')),
('<Control-x>', keyutils.KeySequence.parse('<ctrl+x>')),
('<alt-1>', keyutils.KeySequence.parse('<alt+1>')),
('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', '<blub>', '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', [