diff --git a/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/step_details_page/common/network_data/data_formatting.ts b/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/step_details_page/common/network_data/data_formatting.ts index 8e87bbe657193..8ad55e56ee40a 100644 --- a/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/step_details_page/common/network_data/data_formatting.ts +++ b/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/step_details_page/common/network_data/data_formatting.ts @@ -93,16 +93,26 @@ export const getConnectingTime = (connect?: number, ssl?: number) => { } }; -export const getQueryMatcher = (query?: string): ItemMatcher => { +export const getQueryMatcher = (query?: string): ItemMatcher | undefined => { if (!query) { return (item: NetworkEvent) => true; } - const regExp = new RegExp(query, 'i'); + /* RegExp below taken from: https://github.com/sindresorhus/escape-string-regexp/blob/main/index.js + * First, escape all special character to use an exact string match + * Next, replace escaped '*' with '.' to match any character and support wildcard search */ + const formattedQuery = query.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); + const wildcardQuery = formattedQuery.replaceAll('\\*', '.'); - return (item: NetworkEvent) => { - return (item.url?.search(regExp) ?? -1) > -1; - }; + try { + const regExp = new RegExp(wildcardQuery, 'i'); + + return (item: NetworkEvent) => { + return (item.url?.search(regExp) ?? -1) > -1; + }; + } catch (e) { + // ignore invalid regex + } }; export const getFilterMatcher = (filters: string[] | undefined): ItemMatcher => { diff --git a/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/step_details_page/step_waterfall_chart/waterfall/waterfall_chart_wrapper.test.tsx b/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/step_details_page/step_waterfall_chart/waterfall/waterfall_chart_wrapper.test.tsx index 872e67fcab0c2..c7a033e92c123 100644 --- a/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/step_details_page/step_waterfall_chart/waterfall/waterfall_chart_wrapper.test.tsx +++ b/x-pack/plugins/observability_solution/synthetics/public/apps/synthetics/components/step_details_page/step_waterfall_chart/waterfall/waterfall_chart_wrapper.test.tsx @@ -53,7 +53,7 @@ describe('WaterfallChartWrapper', () => { const filterInput = getByLabelText(FILTER_REQUESTS_LABEL); - const searchText = '.js'; + const searchText = '*.js'; fireEvent.change(filterInput, { target: { value: searchText } });