From cd978693759ab0252a49d702e80ebd1e062861f6 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 9 Mar 2021 14:41:17 -0500 Subject: [PATCH] fix impl Signed-off-by: Sebastian Malton --- src/common/search-store.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/search-store.ts b/src/common/search-store.ts index 75a4100969..7adb0ef107 100644 --- a/src/common/search-store.ts +++ b/src/common/search-store.ts @@ -7,8 +7,8 @@ export class SearchStore { * An utility methods escaping user string to safely pass it into new Regex(variable) * @param value Unescaped string */ - public static escapeRegex(value: string): string { - return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); + public static escapeRegex(value?: string): string { + return value ? value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&") : ""; } /** @@ -70,7 +70,8 @@ export class SearchStore { * @param query Search query from input * @returns Array of line indexes [0, 0, 14, 17, 17, 17, 20...] */ - private findOccurrences(lines: string[] = [], query: string): number[] { + private findOccurrences(lines?: string[], query?: string): number[] { + lines ||= []; const regex = new RegExp(SearchStore.escapeRegex(query), "gi"); return lines