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) => {