From 848bbb5b80db8e06f565d6ac54ce4c185aa3da0c Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 26 Feb 2023 16:46:22 +0100 Subject: [PATCH] Fixed regex crash when looking for `"foo - bar"` --- src/tools/utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tools/utils.ts b/src/tools/utils.ts index b6aa32a..90e7ca9 100644 --- a/src/tools/utils.ts +++ b/src/tools/utils.ts @@ -68,8 +68,9 @@ export function wait(ms: number): Promise { } // https://stackoverflow.com/a/3561711 +// but we enclose special chars in brackets to avoid them being interpreted as regex export function escapeRegex(str: string): string { - return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '[$&]') } /**