SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix(FE): escape regular expression to filter dashboards with special characters (#1279)
rw4nnd21ab7b82d1c
diff --git a/frontend/src/container/ListOfDashboard/SearchFilter/__tests__/utils.test.ts b/frontend/src/container/ListOfDashboard/SearchFilter/__tests__/utils.test.tsnew file mode 100644index 0000000000..db9825b677--- /dev/null+++ b/frontend/src/container/ListOfDashboard/SearchFilter/__tests__/utils.test.ts@@ -0,0 +1,58 @@+import { Dashboard } from 'types/api/dashboard/getAll';+import { v4 as uuid } from 'uuid';++import { TOperator } from '../types';+import { executeSearchQueries } from '../utils';++describe('executeSearchQueries', () => {+ const firstDashboard: Dashboard = {+ id: 11111,+ uuid: uuid(),+ created_at: '',+ updated_at: '',+ data: {+ title: 'first dashboard',+ },+ };+ const secondDashboard: Dashboard = {+ id: 22222,+ uuid: uuid(),+ created_at: '',+ updated_at: '',+ data: {+ title: 'second dashboard',+ },+ };+ const thirdDashboard: Dashboard = {+ id: 333333,+ uuid: uuid(),+ created_at: '',+ updated_at: '',+ data: {+ title: 'third dashboard (with special characters +?\\)',+ },+ };+ const dashboards = [firstDashboard, secondDashboard, thirdDashboard];++ it('should filter dashboards based on title', () => {+ const query = {+ category: 'title',+ id: 'someid',+ operator: '=' as TOperator,+ value: 'first dashboard',+ };++ expect(executeSearchQueries([query], dashboards)).toEqual([firstDashboard]);+ });++ it('should filter dashboards with special characters', () => {+ const query = {+ category: 'title',+ id: 'someid',+ operator: '=' as TOperator,+ value: 'third dashboard (with special characters +?\\)',+ };++ expect(executeSearchQueries([query], dashboards)).toEqual([thirdDashboard]);+ });+});diff --git a/frontend/src/container/ListOfDashboard/SearchFilter/utils.ts b/frontend/src/container/ListOfDashboard/SearchFilter/utils.tsindex 5f9b37cc3e..6487ccd789 100644--- a/frontend/src/container/ListOfDashboard/SearchFilter/utils.ts+++ b/frontend/src/container/ListOfDashboard/SearchFilter/utils.ts@@ -42,6 +42,8 @@ export const executeSearchQueries = (if (!searchData.length || !queries.length) {return searchData;}+ const escapeRegExp = (regExp: string): string =>+ regExp.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');queries.forEach((query: IQueryStructure) => {const { operator } = query;@@ -61,7 +63,7 @@ export const executeSearchQueries = (for (const searchSpaceItem of searchSpace) {if (searchSpaceItem)for (const queryValue of value) {- if (searchSpaceItem.match(queryValue)) {+ if (searchSpaceItem.match(escapeRegExp(queryValue))) {return resolveOperator(true, operator);}}