From fe65d073059138fadae28853c19f37aea7beb2f7 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 7 Mar 2024 19:44:12 -0500 Subject: [PATCH] [8.13] [Synthetics] Allow Synthetics global params to include dashes (#178054) (#178268) # Backport This will backport the following commits from `main` to `8.13`: - [[Synthetics] Allow Synthetics global params to include dashes (#178054)](https://github.com/elastic/kibana/pull/178054) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Justin Kambic --- .../formatters/formatting_utils.test.ts | 20 +++++++++++++++++++ .../formatters/formatting_utils.ts | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/formatting_utils.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/formatting_utils.test.ts index 2fa915e21d070..84e073731aef2 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/formatting_utils.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/formatting_utils.test.ts @@ -20,6 +20,26 @@ describe('replaceStringWithParams', () => { expect(result).toEqual('https://elastic.co'); }); + it('works with dashes in the key', () => { + const result = replaceStringWithParams( + '${home-page-url}', + { 'home-page-url': 'https://elastic.co' }, + logger + ); + + expect(result).toEqual('https://elastic.co'); + }); + + it('works with . in the key', () => { + const result = replaceStringWithParams( + '${home.pageUrl}', + { 'home.pageUrl': 'https://elastic.co' }, + logger + ); + + expect(result).toEqual('https://elastic.co'); + }); + it('returns empty value in case no param', () => { const result = replaceStringWithParams('${homePageUrl}', {}, logger); diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/formatting_utils.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/formatting_utils.ts index d06725b21421e..57d742d08deb0 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/formatting_utils.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/formatting_utils.ts @@ -50,9 +50,10 @@ export const replaceStringWithParams = ( return value as string | null; }; +const SHELL_PARAMS_REGEX = /\$\{[a-zA-Z_][a-zA-Z0-9\._\-?:]*\}/g; + export const hasNoParams = (strVal: string) => { - const shellParamsRegex = /\$\{[a-zA-Z_][a-zA-Z0-9_]*\}/g; - return strVal.match(shellParamsRegex) === null; + return strVal.match(SHELL_PARAMS_REGEX) === null; }; export const secondsToCronFormatter: FormatterFn = (fields, key) => {