From 06ee73f0ed085abfbf27749a27324a5348b36345 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 31 May 2023 17:40:22 -0400 Subject: [PATCH] [8.8] [ResponseOps] Throwing a mustache error when validating action message for warnings (#158668) (#158776) # Backport This will backport the following commits from `main` to `8.8`: - [[ResponseOps] Throwing a mustache error when validating action message for warnings (#158668)](https://github.com/elastic/kibana/pull/158668) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Alexi Doak <109488926+doakalexi@users.noreply.github.com> --- .../lib/validate_params_for_warnings.test.ts | 4 ++++ .../lib/validate_params_for_warnings.ts | 22 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/validate_params_for_warnings.test.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/validate_params_for_warnings.test.ts index 4f3d627c4fcf8..9de5749fbc2b3 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/validate_params_for_warnings.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/validate_params_for_warnings.test.ts @@ -51,4 +51,8 @@ describe('validateParamsForWarnings', () => { test('does not returns warnings when publicUrl is not set and the value is not a string', () => { expect(validateParamsForWarnings(10, undefined, actionVariables)).toBeFalsy(); }); + + test('does not throw an error when passing in invalid mustache', () => { + expect(() => validateParamsForWarnings('{{', undefined, actionVariables)).not.toThrowError(); + }); }); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/validate_params_for_warnings.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/validate_params_for_warnings.ts index fe7d2b0e5ffb5..d361d6f739cdc 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/validate_params_for_warnings.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/validate_params_for_warnings.ts @@ -31,14 +31,20 @@ export function validateParamsForWarnings( return acc; }, new Array()); - const variables = new Set( - (Mustache.parse(value) as Array<[string, string]>) - .filter(([type]) => type === 'name') - .map(([, v]) => v) - ); - const hasUrlFields = some(publicUrlFields, (publicUrlField) => variables.has(publicUrlField)); - if (hasUrlFields) { - return publicUrlWarning; + try { + const variables = new Set( + (Mustache.parse(value) as Array<[string, string]>) + .filter(([type]) => type === 'name') + .map(([, v]) => v) + ); + const hasUrlFields = some(publicUrlFields, (publicUrlField) => variables.has(publicUrlField)); + if (hasUrlFields) { + return publicUrlWarning; + } + } catch (e) { + /* + * do nothing, we don't care if the mustache is invalid + */ } } return null;