From 0e467982354f71f9244594d8fa3e8734e8346d81 Mon Sep 17 00:00:00 2001 From: Tiago Costa Date: Tue, 16 Jul 2024 07:14:22 +0100 Subject: [PATCH] [7.17] [ML] Removing use of re2 library (#186104) (#188372) # Backport This will backport the following commits from `main` to `7.17`: - [[ML] Removing use of re2 library (#186104)](https://github.com/elastic/kibana/pull/186104) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) --------- Co-authored-by: James Gowdy --- .../saved_objects/initialization/space_overrides/logs.ts | 3 +-- .../saved_objects/initialization/space_overrides/metrics.ts | 3 +-- x-pack/plugins/ml/server/saved_objects/service.ts | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts index 40285742af2b9..0103d8eb5d0ab 100644 --- a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts +++ b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/logs.ts @@ -6,7 +6,6 @@ */ import { IScopedClusterClient } from 'kibana/server'; -import RE2 from 're2'; import { mlLog } from '../../../lib/log'; import { Job } from '../../../../common/types/anomaly_detection_jobs'; @@ -43,7 +42,7 @@ export async function logJobsSpaces({ } function findLogJobSpaceFactory() { - const reg = new RE2(`${MODULE_PREFIX}-(.+)-(${SOURCES.join('|')})-(${JOB_IDS.join('|')})`); + const reg = new RegExp(`${MODULE_PREFIX}-(.+)-(${SOURCES.join('|')})-(${JOB_IDS.join('|')})`); return (jobId: string) => { const result = reg.exec(jobId); diff --git a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts index 125b3e32b1efb..1d2173ecd29f7 100644 --- a/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts +++ b/x-pack/plugins/ml/server/saved_objects/initialization/space_overrides/metrics.ts @@ -6,7 +6,6 @@ */ import { IScopedClusterClient } from 'kibana/server'; -import RE2 from 're2'; import { mlLog } from '../../../lib/log'; import { Job } from '../../../../common/types/anomaly_detection_jobs'; @@ -50,7 +49,7 @@ export async function metricsJobsSpaces({ } function findMetricsJobSpaceFactory() { - const reg = new RE2(`${MODULE_PREFIX}-(.+)-(${SOURCES.join('|')})-(${JOB_IDS.join('|')})`); + const reg = new RegExp(`${MODULE_PREFIX}-(.+)-(${SOURCES.join('|')})-(${JOB_IDS.join('|')})`); return (jobId: string) => { const result = reg.exec(jobId); diff --git a/x-pack/plugins/ml/server/saved_objects/service.ts b/x-pack/plugins/ml/server/saved_objects/service.ts index ff8856457ca4f..6907842b262a9 100644 --- a/x-pack/plugins/ml/server/saved_objects/service.ts +++ b/x-pack/plugins/ml/server/saved_objects/service.ts @@ -5,7 +5,6 @@ * 2.0. */ -import RE2 from 're2'; import { KibanaRequest, SavedObjectsClientContract, @@ -281,7 +280,7 @@ export function jobSavedObjectServiceFactory( if (id.match('\\*') === null) { return jobIds.includes(id); } - const regex = new RE2(id.replace('*', '.*')); + const regex = new RegExp(id.replace('*', '.*')); return jobIds.some((jId) => typeof jId === 'string' && regex.exec(jId)); }); }