Skip to content

Commit

Permalink
fix: validate that remappings are string arrays (#3440)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoon authored Feb 1, 2019
1 parent cff1093 commit 3072338
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Configuration implements IConfiguration {

const modeKeyBindingsMap = new Map<string, IKeyRemapping>();
for (let i = keybindings.length - 1; i >= 0; i--) {
let remapping = keybindings[i];
let remapping = keybindings[i] as IKeyRemapping;

// validate
let remappingErrors = await configurationValidator.isRemappingValid(remapping);
Expand Down
12 changes: 12 additions & 0 deletions src/configuration/configurationValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ class ConfigurationValidator {
return [{ level: 'error', message: `${remapping.before} missing 'after' key or 'command'.` }];
}

if (!(remapping.before instanceof Array)) {
return [
{ level: 'error', message: `Remapping of '${remapping.before}' should be a string array.` },
];
}

if (remapping.after && !(remapping.after instanceof Array)) {
return [
{ level: 'error', message: `Remapping of '${remapping.after}' should be a string array.` },
];
}

if (remapping.commands) {
for (const command of remapping.commands) {
let cmd: string;
Expand Down
3 changes: 2 additions & 1 deletion src/configuration/remapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class Remapper implements IRemapper {
for (let sliceLength = startingSliceLength; sliceLength >= range[0]; sliceLength--) {
const keySlice = inputtedKeys.slice(-sliceLength).join('');

this._logger.verbose(`trying to find matching remap for keySlice=${keySlice}.`);
this._logger.verbose(`key=${inputtedKeys}. keySlice=${keySlice}.`);
if (userDefinedRemappings.has(keySlice)) {
// In Insert mode, we allow users to precede remapped commands
// with extraneous keystrokes (eg. "hello world jj")
Expand All @@ -208,6 +208,7 @@ export class Remapper implements IRemapper {
.slice(0, inputtedKeys.length - keySlice.length)
.join('');
if (precedingKeys.length > 0 && !/^[0-9]+$/.test(precedingKeys)) {
this._logger.verbose(`key sequences need to match precisely. precedingKeys=${precedingKeys}.`);
break;
}
}
Expand Down

0 comments on commit 3072338

Please sign in to comment.