Skip to content

Commit

Permalink
Escape special characters in regex expression
Browse files Browse the repository at this point in the history
Fix #1059
  • Loading branch information
AliceR committed Oct 21, 2024
1 parent 46e1c5d commit 9c338ab
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/scripts/components/common/text-highlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default function TextHighlight(props: TextHighlightProps) {

// Highlight is done index based because it has to take case insensitive
// searches into account.
const regex = new RegExp(value, 'ig');
const escapedValue = value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp(escapedValue, 'ig');

/* eslint-disable-next-line prefer-const */
let highlighted: ReactNode[] = [];
let workingIdx = 0;
Expand Down

0 comments on commit 9c338ab

Please sign in to comment.