mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-04-28 00:30:13 +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 =
|
const inputSubstr =
|
||||||
input.substring(0, this.getCaretPositionEnd() || 0) || input;
|
input.substring(0, this.getCaretPositionEnd() || 0) || input;
|
||||||
const regexp = new RegExp(
|
const regexp = new RegExp(
|
||||||
`${layoutCandidate}$`,
|
`${this.utilities.escapeRegex(layoutCandidate)}$`,
|
||||||
layoutCandidatesCaseSensitiveMatch ? "g" : "gi"
|
layoutCandidatesCaseSensitiveMatch ? "g" : "gi"
|
||||||
);
|
);
|
||||||
const matches = [...inputSubstr.matchAll(regexp)];
|
const matches = [...inputSubstr.matchAll(regexp)];
|
||||||
@ -387,7 +387,7 @@ class SimpleKeyboard {
|
|||||||
currentInput;
|
currentInput;
|
||||||
|
|
||||||
const regexp = new RegExp(
|
const regexp = new RegExp(
|
||||||
`${candidateKey}$`,
|
`${this.utilities.escapeRegex(candidateKey)}$`,
|
||||||
layoutCandidatesCaseSensitiveMatch ? "g" : "gi"
|
layoutCandidatesCaseSensitiveMatch ? "g" : "gi"
|
||||||
);
|
);
|
||||||
const newInputSubstr = inputSubstr.replace(
|
const newInputSubstr = inputSubstr.replace(
|
||||||
|
@ -532,6 +532,13 @@ class Utilities {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape regex input
|
||||||
|
*/
|
||||||
|
escapeRegex(str: string) {
|
||||||
|
return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reusable empty function
|
* Reusable empty function
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user