diff --git a/frontend/src/Editor/Components/DropdownV2/utils.js b/frontend/src/Editor/Components/DropdownV2/utils.js index ed58cbe73d..814b7b341a 100644 --- a/frontend/src/Editor/Components/DropdownV2/utils.js +++ b/frontend/src/Editor/Components/DropdownV2/utils.js @@ -52,7 +52,14 @@ export const getInputBackgroundColor = ({ fieldBackgroundColor, darkMode, isLoad }; export const highlightText = (text = '', highlight) => { - const parts = text?.split(new RegExp(`(${highlight})`, 'gi')); + // Escape special regex characters in the highlight string + const escapeRegExp = (string) => { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + }; + + const safeHighlight = highlight ? escapeRegExp(highlight) : ''; + const parts = text?.split(new RegExp(`(${safeHighlight})`, 'gi')); + return ( {parts.map((part, index) =>