Skip to content

Commit b1224af

Browse files
[9.0] Update Mustache to v4 (main) (#206184) (#220571)
# Backport This will backport the following commits from `main` to `9.0`: - [Update Mustache to v4 (main) (#206184)](#206184) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"elastic-renovate-prod[bot]","email":"174716857+elastic-renovate-prod[bot]@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-05-08T15:43:36Z","message":"Update Mustache to v4 (main) (#206184)\n\nupdates the `mustache` package from `^2.3.2` to `^4.2.0`, as well as the associated types package","sha":"4dd8e6ee5143a1db8e2edbc1387a48f5874f914b","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","Team:obs-ux-infra_services","v9.1.0"],"title":"Update Mustache to v4 (main)","number":206184,"url":"https://github.com/elastic/kibana/pull/206184","mergeCommit":{"message":"Update Mustache to v4 (main) (#206184)\n\nupdates the `mustache` package from `^2.3.2` to `^4.2.0`, as well as the associated types package","sha":"4dd8e6ee5143a1db8e2edbc1387a48f5874f914b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206184","number":206184,"mergeCommit":{"message":"Update Mustache to v4 (main) (#206184)\n\nupdates the `mustache` package from `^2.3.2` to `^4.2.0`, as well as the associated types package","sha":"4dd8e6ee5143a1db8e2edbc1387a48f5874f914b"}}]}] BACKPORT--> --------- Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>
1 parent 5e9045a commit b1224af

File tree

7 files changed

+17
-28
lines changed

7 files changed

+17
-28
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@
11921192
"monaco-editor": "^0.44.0",
11931193
"monaco-yaml": "^5.1.0",
11941194
"murmurhash": "^2.0.1",
1195-
"mustache": "^2.3.2",
1195+
"mustache": "^4.2.0",
11961196
"node-diff3": "^3.1.2",
11971197
"node-fetch": "^2.6.7",
11981198
"node-forge": "^1.3.1",
@@ -1631,7 +1631,7 @@
16311631
"@types/minimist": "^1.2.5",
16321632
"@types/mock-fs": "^4.13.1",
16331633
"@types/moment-duration-format": "^2.2.3",
1634-
"@types/mustache": "^0.8.31",
1634+
"@types/mustache": "^4.2.5",
16351635
"@types/nock": "^10.0.3",
16361636
"@types/node": "20.10.5",
16371637
"@types/node-fetch": "2.6.4",

src/platform/packages/shared/response-ops/rule_form/src/validation/validate_params_for_warnings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const validateParamsForWarnings = ({
3737

3838
try {
3939
const variables = new Set(
40-
(Mustache.parse(value) as Array<[string, string]>)
40+
Mustache.parse(value)
4141
.filter(([type]) => type === 'name')
4242
.map(([, v]) => v)
4343
);

src/platform/plugins/shared/home/public/application/components/tutorial/replace_template_strings.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { Writer } from 'mustache';
10+
import Mustache from 'mustache';
1111
import { getServices } from '../../kibana_services';
1212

1313
const TEMPLATE_TAGS = ['{', '}'];
1414

15-
// Can not use 'Mustache' since its a global object
16-
const mustacheWriter = new Writer();
17-
// do not html escape output
18-
mustacheWriter.escapedValue = function escapedValue(token, context) {
19-
const value = context.lookup(token[1]);
20-
if (value != null) {
21-
return value;
22-
}
23-
};
24-
15+
// replace template strings without the default mustache escaping
2516
export function replaceTemplateStrings(text, params = {}) {
2617
const { tutorialService, kibanaVersion, docLinks } = getServices();
2718

@@ -50,6 +41,9 @@ export function replaceTemplateStrings(text, params = {}) {
5041
},
5142
params: params,
5243
};
53-
mustacheWriter.parse(text, TEMPLATE_TAGS);
54-
return mustacheWriter.render(text, variables);
44+
const config = {
45+
tags: TEMPLATE_TAGS,
46+
escape: (s) => s,
47+
};
48+
return Mustache.render(text, variables, undefined, config);
5549
}

x-pack/platform/plugins/shared/triggers_actions_ui/public/application/lib/validate_params_for_warnings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function validateParamsForWarnings(
3434

3535
try {
3636
const variables = new Set(
37-
(Mustache.parse(value) as Array<[string, string]>)
37+
Mustache.parse(value)
3838
.filter(([type]) => type === 'name')
3939
.map(([, v]) => v)
4040
);

x-pack/solutions/observability/plugins/apm/public/components/app/settings/custom_link/create_edit_custom_link_flyout/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const getSelectOptions = (filters: Filter[], selectedKey: Filter['key'])
4848
};
4949

5050
const getInvalidTemplateVariables = (template: string, transaction: Transaction) => {
51-
return (Mustache.parse(template) as Array<[string, string]>)
51+
return Mustache.parse(template)
5252
.filter(([type]) => type === 'name')
5353
.map(([, value]) => value)
5454
.filter((templateVar) => get(transaction, templateVar) == null);

x-pack/solutions/observability/plugins/apm/public/components/fleet_integration/apm_agents/render_mustache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import type { DocLinksStart } from '@kbn/core/public';
99
import Mustache from 'mustache';
1010

11-
const TEMPLATE_TAGS = ['{', '}'];
11+
const TEMPLATE_TAGS: [string, string] = ['{', '}'];
1212

1313
export function renderMustache({
1414
text,

yarn.lock

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11443,10 +11443,10 @@
1144311443
dependencies:
1144411444
moment ">=2.14.0"
1144511445

11446-
"@types/mustache@^0.8.31":
11447-
version "0.8.31"
11448-
resolved "https://registry.yarnpkg.com/@types/mustache/-/mustache-0.8.31.tgz#7c86cbf74f7733f9e3bdc28817623927eb386616"
11449-
integrity sha512-72flCZJkEJHPwhmpHgg4a0ZBLssMhg5NB0yltRblRlZMo4py3B/u/d7icevc4EeN9MPQUo/dPtuVOoVy9ih6cQ==
11446+
"@types/mustache@^4.2.5":
11447+
version "4.2.5"
11448+
resolved "https://registry.yarnpkg.com/@types/mustache/-/mustache-4.2.5.tgz#9129f0d6857f976e00e171bbb3460e4b702f84ef"
11449+
integrity sha512-PLwiVvTBg59tGFL/8VpcGvqOu3L4OuveNvPi0EYbWchRdEVP++yRUXJPFl+CApKEq13017/4Nf7aQ5lTtHUNsA==
1145011450

1145111451
"@types/nock@^10.0.3":
1145211452
version "10.0.3"
@@ -23570,11 +23570,6 @@ murmurhash@^2.0.1:
2357023570
resolved "https://registry.yarnpkg.com/murmurhash/-/murmurhash-2.0.1.tgz#4097720e08cf978872194ad84ea5be2dec9b610f"
2357123571
integrity sha512-5vQEh3y+DG/lMPM0mCGPDnyV8chYg/g7rl6v3Gd8WMF9S429ox3Xk8qrk174kWhG767KQMqqxLD1WnGd77hiew==
2357223572

23573-
mustache@^2.3.2:
23574-
version "2.3.2"
23575-
resolved "https://registry.yarnpkg.com/mustache/-/mustache-2.3.2.tgz#a6d4d9c3f91d13359ab889a812954f9230a3d0c5"
23576-
integrity sha512-KpMNwdQsYz3O/SBS1qJ/o3sqUJ5wSb8gb0pul8CO0S56b9Y2ALm8zCfsjPXsqGFfoNBkDwZuZIAjhsZI03gYVQ==
23577-
2357823573
mustache@^4.2.0:
2357923574
version "4.2.0"
2358023575
resolved "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz"

0 commit comments

Comments
 (0)