Now the special characters in the search value are escapec before constructing the regexp. (#3057)

This commit is contained in:
Sanjai Kumar 2024-09-11 10:52:11 +05:30 committed by GitHub
parent 1c0ff13483
commit 0b4e9e7640
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@
*/ */
import React from 'react'; import React from 'react';
import isEqual from 'lodash/isEqual'; import { isEqual, escapeRegExp } from 'lodash';
import { getEnvironmentVariables } from 'utils/collections'; import { getEnvironmentVariables } from 'utils/collections';
import { defineCodeMirrorBrunoVariablesMode } from 'utils/common/codemirror'; import { defineCodeMirrorBrunoVariablesMode } from 'utils/common/codemirror';
import StyledWrapper from './StyledWrapper'; import StyledWrapper from './StyledWrapper';
@ -406,7 +406,8 @@ export default class CodeEditor extends React.Component {
const searchInput = document.querySelector('.CodeMirror-search-field'); const searchInput = document.querySelector('.CodeMirror-search-field');
if (searchInput && searchInput.value.length > 0) { 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); const matches = this.editor.getValue().match(text);
count = matches ? matches.length : 0; count = matches ? matches.length : 0;
} }