Skip to content

Commit

Permalink
Safely escaped special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia committed Oct 30, 2024
1 parent 94be2ad commit cfa46b2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion frontend/src/services/ForestClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export const highlightMatch = (itemName: string, searchTerm: string): string =>
const trimmedSearchTerm = searchTerm.trim();
if (!trimmedSearchTerm) return itemName;

const regex = new RegExp(`(${trimmedSearchTerm})`, 'i');
// Escape special characters in the search term
const escapedSearchTerm = trimmedSearchTerm.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
const regex = new RegExp(`(${escapedSearchTerm})`, 'i');
const parts = itemName.split(regex);

return parts
Expand Down

0 comments on commit cfa46b2

Please sign in to comment.