From 475c9f7f8915d33c774a3fc02be01a75da59f55a Mon Sep 17 00:00:00 2001 From: Sambhavi Pandey <48976443+pandeysambhi@users.noreply.github.com> Date: Fri, 25 Jul 2025 04:01:07 +0530 Subject: [PATCH] fix(queryRegex): safe escape for query regex (#4493) Co-authored-by: Sambhavi Pandey --- src/utils/formatUtil.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/formatUtil.ts b/src/utils/formatUtil.ts index 7b7966394..da933d3ec 100644 --- a/src/utils/formatUtil.ts +++ b/src/utils/formatUtil.ts @@ -39,7 +39,11 @@ export function trimJsonExt(path?: string) { export function highlightQuery(text: string, query: string) { if (!query) return text - const regex = new RegExp(`(${query})`, 'gi') + + // Escape special regex characters in the query string + const escapedQuery = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + + const regex = new RegExp(`(${escapedQuery})`, 'gi') return text.replace(regex, '$1') }