Escape regex input for layoutCandidates check. Fixes #1645

This commit is contained in:
Francisco Hodge 2022-07-31 16:42:01 -07:00
parent 5c574e8226
commit f82f2c342f
11 changed files with 20362 additions and 789 deletions

19632
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -332,7 +332,7 @@ class SimpleKeyboard {
const inputSubstr =
input.substring(0, this.getCaretPositionEnd() || 0) || input;
const regexp = new RegExp(
`${layoutCandidate}$`,
`${this.utilities.escapeRegex(layoutCandidate)}$`,
layoutCandidatesCaseSensitiveMatch ? "g" : "gi"
);
const matches = [...inputSubstr.matchAll(regexp)];
@ -387,7 +387,7 @@ class SimpleKeyboard {
currentInput;
const regexp = new RegExp(
`${candidateKey}$`,
`${this.utilities.escapeRegex(candidateKey)}$`,
layoutCandidatesCaseSensitiveMatch ? "g" : "gi"
);
const newInputSubstr = inputSubstr.replace(

View File

@ -532,6 +532,13 @@ class Utilities {
);
}
/**
* Escape regex input
*/
escapeRegex(str: string) {
return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
/**
* Reusable empty function
*/