Skip to content

Commit bdf7d29

Browse files
authored
fix: [lw-11926] catch unvalid regex error in word list search util (#1581)
1 parent ac7c30c commit bdf7d29

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/core/src/ui/utils/word-list-search.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export const wordListSearch = (
1818
if (!searchWord || !wordList?.length) return suggestionList;
1919

2020
const parsedSearchWord = isCaseSensitive ? searchWord : searchWord.toLowerCase();
21+
let parsedSearchWordRegExp;
22+
try {
23+
parsedSearchWordRegExp = new RegExp(`^${parsedSearchWord}.*$`);
24+
} catch {
25+
return suggestionList;
26+
}
2127

2228
while (continueSearching) {
2329
const currentWord = wordList[currentWordIdx];
@@ -36,10 +42,9 @@ export const wordListSearch = (
3642
}
3743

3844
for (let idx = 0; idx < suggestionListLength; idx++) {
39-
const startWith = new RegExp(`^${parsedSearchWord}.*$`);
4045
const currentWord = wordList[currentWordIdx + idx];
4146

42-
if (startWith.test(currentWord)) {
47+
if (parsedSearchWordRegExp.test(currentWord)) {
4348
suggestionList.push(currentWord);
4449
}
4550
}

0 commit comments

Comments
 (0)