fix(queryRegex): safe escape for query regex (#4493)

Co-authored-by: Sambhavi Pandey <sambhavi.pandey@aexp.com>
This commit is contained in:
Sambhavi Pandey
2025-07-25 04:01:07 +05:30
committed by GitHub
parent e0aac8c9db
commit 475c9f7f89

View File

@@ -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, '<span class="highlight">$1</span>')
}