Skip to content

Commit

Permalink
fix: [lw-11926] catch unvalid regex error in word list search util (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore authored Dec 10, 2024
1 parent ac7c30c commit bdf7d29
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/ui/utils/word-list-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const wordListSearch = (
if (!searchWord || !wordList?.length) return suggestionList;

const parsedSearchWord = isCaseSensitive ? searchWord : searchWord.toLowerCase();
let parsedSearchWordRegExp;
try {
parsedSearchWordRegExp = new RegExp(`^${parsedSearchWord}.*$`);
} catch {
return suggestionList;
}

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

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

if (startWith.test(currentWord)) {
if (parsedSearchWordRegExp.test(currentWord)) {
suggestionList.push(currentWord);
}
}
Expand Down

0 comments on commit bdf7d29

Please sign in to comment.