Validate user-written keybindings (#10452)
This commit is contained in:
parent
1581634980
commit
a3493c7593
2 changed files with 43 additions and 5 deletions
|
@ -408,11 +408,24 @@ export class IOSupport {
|
|||
}
|
||||
|
||||
public static readKeybindingItem(input: IUserFriendlyKeybinding, index: number): IKeybindingItem {
|
||||
let key = IOSupport.readKeybinding(input.key);
|
||||
let when = IOSupport.readKeybindingWhen(input.when);
|
||||
let key:number = 0;
|
||||
if (typeof input.key === 'string') {
|
||||
key = IOSupport.readKeybinding(input.key);
|
||||
}
|
||||
|
||||
let when:ContextKeyExpr = null;
|
||||
if (typeof input.when === 'string') {
|
||||
when = IOSupport.readKeybindingWhen(input.when);
|
||||
}
|
||||
|
||||
let command:string = null;
|
||||
if (typeof input.command === 'string') {
|
||||
command = input.command;
|
||||
}
|
||||
|
||||
return {
|
||||
keybinding: key,
|
||||
command: input.command,
|
||||
command: command,
|
||||
when: when,
|
||||
weight1: 1000,
|
||||
weight2: index
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import {ISimplifiedPlatform, KeyCode, KeyMod} from 'vs/base/common/keyCodes';
|
||||
import {IOSupport} from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import {NormalizedKeybindingItem, IOSupport} from 'vs/platform/keybinding/common/keybindingResolver';
|
||||
import {IUserFriendlyKeybinding} from 'vs/platform/keybinding/common/keybinding';
|
||||
|
||||
suite('Keybinding IO', () => {
|
||||
|
||||
|
@ -110,4 +111,28 @@ suite('Keybinding IO', () => {
|
|||
testDeserialization(' ctrl-shift-alt-win-A ', ' shift-alt-cmd-Ctrl-A ', ' ctrl-shift-alt-META-A ', KeyMod.CtrlCmd | KeyMod.Shift | KeyMod.Alt | KeyMod.WinCtrl | KeyCode.KEY_A);
|
||||
});
|
||||
|
||||
|
||||
test('issue #10452 - invalid command', () => {
|
||||
let strJSON = `[{ "key": "ctrl+k ctrl+f", "command": ["firstcommand", "seccondcommand"] }]`;
|
||||
let userKeybinding = <IUserFriendlyKeybinding>JSON.parse(strJSON)[0];
|
||||
let keybindingItem = IOSupport.readKeybindingItem(userKeybinding, 0);
|
||||
let normalizedKeybindingItem = NormalizedKeybindingItem.fromKeybindingItem(keybindingItem, false);
|
||||
assert.equal(normalizedKeybindingItem.command, null);
|
||||
});
|
||||
|
||||
test('issue #10452 - invalid when', () => {
|
||||
let strJSON = `[{ "key": "ctrl+k ctrl+f", "command": "firstcommand", "when": [] }]`;
|
||||
let userKeybinding = <IUserFriendlyKeybinding>JSON.parse(strJSON)[0];
|
||||
let keybindingItem = IOSupport.readKeybindingItem(userKeybinding, 0);
|
||||
let normalizedKeybindingItem = NormalizedKeybindingItem.fromKeybindingItem(keybindingItem, false);
|
||||
assert.equal(normalizedKeybindingItem.when, null);
|
||||
});
|
||||
|
||||
test('issue #10452 - invalid key', () => {
|
||||
let strJSON = `[{ "key": [], "command": "firstcommand" }]`;
|
||||
let userKeybinding = <IUserFriendlyKeybinding>JSON.parse(strJSON)[0];
|
||||
let keybindingItem = IOSupport.readKeybindingItem(userKeybinding, 0);
|
||||
let normalizedKeybindingItem = NormalizedKeybindingItem.fromKeybindingItem(keybindingItem, false);
|
||||
assert.equal(normalizedKeybindingItem.keybinding, 0);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue