From 0b4e9e76404c4077c6250351c00cadb6189d4fdb Mon Sep 17 00:00:00 2001 From: Sanjai Kumar <84461672+sanjai0py@users.noreply.github.com> Date: Wed, 11 Sep 2024 10:52:11 +0530 Subject: [PATCH] Now the special characters in the search value are escapec before constructing the regexp. (#3057) --- packages/bruno-app/src/components/CodeEditor/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/bruno-app/src/components/CodeEditor/index.js b/packages/bruno-app/src/components/CodeEditor/index.js index 0b12e68d6..0b4187e5f 100644 --- a/packages/bruno-app/src/components/CodeEditor/index.js +++ b/packages/bruno-app/src/components/CodeEditor/index.js @@ -6,7 +6,7 @@ */ import React from 'react'; -import isEqual from 'lodash/isEqual'; +import { isEqual, escapeRegExp } from 'lodash'; import { getEnvironmentVariables } from 'utils/collections'; import { defineCodeMirrorBrunoVariablesMode } from 'utils/common/codemirror'; import StyledWrapper from './StyledWrapper'; @@ -406,7 +406,8 @@ export default class CodeEditor extends React.Component { const searchInput = document.querySelector('.CodeMirror-search-field'); if (searchInput && searchInput.value.length > 0) { - const text = new RegExp(searchInput.value, 'gi'); + // Escape special characters in search input to prevent RegExp crashes. Fixes #3051 + const text = new RegExp(escapeRegExp(searchInput.value), 'gi'); const matches = this.editor.getValue().match(text); count = matches ? matches.length : 0; }