Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
(filterServiceStatusIncidents): fix issue in regex for some cases of …
Browse files Browse the repository at this point in the history
…tickers breaking the filter
  • Loading branch information
LFBarreto committed Dec 3, 2021
1 parent 4203d87 commit 38ebd6a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/notifications/ServiceStatusProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ export function useServiceStatus(): StatusContextType {
return useContext(ServiceStatusContext);
}

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}

export function filterServiceStatusIncidents(
incidents: Incident[],
tickers: string[] = []
): Incident[] {
if (!tickers || tickers.length === 0) return [];

const tickersRegex = new RegExp(tickers.join("|"), "i");
const tickersRegex = new RegExp(escapeRegExp(tickers.join("|")), "i");
return incidents.filter(
({ components }) =>
!components || // dont filter out if no components
Expand Down

0 comments on commit 38ebd6a

Please sign in to comment.