mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-02-22 01:29:39 +08:00
Escape regex input for layoutCandidates check. Fixes #1645
This commit is contained in:
parent
5c574e8226
commit
f82f2c342f
19632
package-lock.json
generated
19632
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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(
|
||||
|
@ -532,6 +532,13 @@ class Utilities {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape regex input
|
||||
*/
|
||||
escapeRegex(str: string) {
|
||||
return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reusable empty function
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user