mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
# Backport This will backport the following commits from `main` to `8.6`: - [Add custom Buildkite pipeline for @kbn/handlebars (#146964)](https://github.com/elastic/kibana/pull/146964) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Thomas Watson","email":"watson@elastic.co"},"sourceCommit":{"committedDate":"2022-12-08T17:28:33Z","message":"Add custom Buildkite pipeline for @kbn/handlebars (#146964)\n\nCloses #146963","sha":"39d27bb868ba5e0d544a0fa17afb19abf650c7bf","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","v8.7.0"],"number":146964,"url":"https://github.com/elastic/kibana/pull/146964","mergeCommit":{"message":"Add custom Buildkite pipeline for @kbn/handlebars (#146964)\n\nCloses #146963","sha":"39d27bb868ba5e0d544a0fa17afb19abf650c7bf"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/146964","number":146964,"mergeCommit":{"message":"Add custom Buildkite pipeline for @kbn/handlebars (#146964)\n\nCloses #146963","sha":"39d27bb868ba5e0d544a0fa17afb19abf650c7bf"}}]}] BACKPORT--> Co-authored-by: Thomas Watson <watson@elastic.co>
This commit is contained in:
parent
a232b21207
commit
f67c20d32f
15 changed files with 323 additions and 235 deletions
11
.buildkite/pipelines/pull_request/kbn_handlebars.yml
Normal file
11
.buildkite/pipelines/pull_request/kbn_handlebars.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
steps:
|
||||
- command: .buildkite/scripts/steps/test/kbn_handlebars.sh
|
||||
label: 'Check @kbn/handlebars for upstream differences'
|
||||
agents:
|
||||
queue: n2-2-spot
|
||||
depends_on: build
|
||||
timeout_in_minutes: 5
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: '*'
|
||||
limit: 1
|
|
@ -54,6 +54,10 @@ const uploadPipeline = (pipelineContent: string | object) => {
|
|||
|
||||
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/base.yml', false));
|
||||
|
||||
if (await doAnyChangesMatch([/^packages\/kbn-handlebars/])) {
|
||||
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/kbn_handlebars.yml'));
|
||||
}
|
||||
|
||||
if (
|
||||
(await doAnyChangesMatch([
|
||||
/^packages\/kbn-securitysolution-.*/,
|
||||
|
|
8
.buildkite/scripts/steps/test/kbn_handlebars.sh
Executable file
8
.buildkite/scripts/steps/test/kbn_handlebars.sh
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source .buildkite/scripts/common/util.sh
|
||||
|
||||
echo '--- Checking for @kbn/handlebars test changes'
|
||||
packages/kbn-handlebars/scripts/check_for_test_changes.sh
|
|
@ -1,15 +1,5 @@
|
|||
1,11c1,21
|
||||
1c1,6
|
||||
< global.handlebarsEnv = null;
|
||||
<
|
||||
< beforeEach(function() {
|
||||
< global.handlebarsEnv = Handlebars.create();
|
||||
< });
|
||||
<
|
||||
< describe('basic context', function() {
|
||||
< it('most basic', function() {
|
||||
< expectTemplate('{{foo}}')
|
||||
< .withInput({ foo: 'foo' })
|
||||
< .toCompileTo('foo');
|
||||
---
|
||||
> /*
|
||||
> * This file is forked from the handlebars project (https://github.com/handlebars-lang/handlebars.js),
|
||||
|
@ -17,22 +7,24 @@
|
|||
> * Elasticsearch B.V. licenses this file to you under the MIT License.
|
||||
> * See `packages/kbn-handlebars/LICENSE` for more information.
|
||||
> */
|
||||
>
|
||||
3,5c8,9
|
||||
< beforeEach(function() {
|
||||
< global.handlebarsEnv = Handlebars.create();
|
||||
< });
|
||||
---
|
||||
> import Handlebars from '../..';
|
||||
> import { expectTemplate } from '../__jest__/test_bench';
|
||||
>
|
||||
7,11c11,13
|
||||
< describe('basic context', function() {
|
||||
< it('most basic', function() {
|
||||
< expectTemplate('{{foo}}')
|
||||
< .withInput({ foo: 'foo' })
|
||||
< .toCompileTo('foo');
|
||||
---
|
||||
> describe('basic context', () => {
|
||||
> it('most basic', () => {
|
||||
> expectTemplate('{{foo}}').withInput({ foo: 'foo' }).toCompileTo('foo');
|
||||
> });
|
||||
>
|
||||
> it('escaping', () => {
|
||||
> expectTemplate('\\{{foo}}').withInput({ foo: 'food' }).toCompileTo('{{foo}}');
|
||||
> expectTemplate('content \\{{foo}}').withInput({ foo: 'food' }).toCompileTo('content {{foo}}');
|
||||
> expectTemplate('\\\\{{foo}}').withInput({ foo: 'food' }).toCompileTo('\\food');
|
||||
> expectTemplate('content \\\\{{foo}}').withInput({ foo: 'food' }).toCompileTo('content \\food');
|
||||
> expectTemplate('\\\\ {{foo}}').withInput({ foo: 'food' }).toCompileTo('\\\\ food');
|
||||
14,36c24
|
||||
14,33c16,21
|
||||
< it('escaping', function() {
|
||||
< expectTemplate('\\{{foo}}')
|
||||
< .withInput({ foo: 'food' })
|
||||
|
@ -53,8 +45,14 @@
|
|||
< expectTemplate('\\\\ {{foo}}')
|
||||
< .withInput({ foo: 'food' })
|
||||
< .toCompileTo('\\\\ food');
|
||||
< });
|
||||
<
|
||||
---
|
||||
> it('escaping', () => {
|
||||
> expectTemplate('\\{{foo}}').withInput({ foo: 'food' }).toCompileTo('{{foo}}');
|
||||
> expectTemplate('content \\{{foo}}').withInput({ foo: 'food' }).toCompileTo('content {{foo}}');
|
||||
> expectTemplate('\\\\{{foo}}').withInput({ foo: 'food' }).toCompileTo('\\food');
|
||||
> expectTemplate('content \\\\{{foo}}').withInput({ foo: 'food' }).toCompileTo('content \\food');
|
||||
> expectTemplate('\\\\ {{foo}}').withInput({ foo: 'food' }).toCompileTo('\\\\ food');
|
||||
36c24
|
||||
< it('compiling with a basic context', function() {
|
||||
---
|
||||
> it('compiling with a basic context', () => {
|
||||
|
@ -199,7 +197,7 @@
|
|||
> it('newlines', () => {
|
||||
190d150
|
||||
<
|
||||
194,223c154,160
|
||||
194,216c154,159
|
||||
< it('escaping text', function() {
|
||||
< expectTemplate("Awesome's")
|
||||
< .withMessage(
|
||||
|
@ -223,13 +221,6 @@
|
|||
< expectTemplate(" ' ' ")
|
||||
< .withMessage('double quotes never produce invalid javascript')
|
||||
< .toCompileTo(" ' ' ");
|
||||
< });
|
||||
<
|
||||
< it('escaping expressions', function() {
|
||||
< expectTemplate('{{{awesome}}}')
|
||||
< .withInput({ awesome: "&'\\<>" })
|
||||
< .withMessage("expressions with 3 handlebars aren't escaped")
|
||||
< .toCompileTo("&'\\<>");
|
||||
---
|
||||
> it('escaping text', () => {
|
||||
> expectTemplate("Awesome's").toCompileTo("Awesome's");
|
||||
|
@ -237,16 +228,21 @@
|
|||
> expectTemplate('Awesome\\\\ foo').toCompileTo('Awesome\\\\ foo');
|
||||
> expectTemplate('Awesome {{foo}}').withInput({ foo: '\\' }).toCompileTo('Awesome \\');
|
||||
> expectTemplate(" ' ' ").toCompileTo(" ' ' ");
|
||||
> });
|
||||
225,228c162,165
|
||||
219,223c162,163
|
||||
< it('escaping expressions', function() {
|
||||
< expectTemplate('{{{awesome}}}')
|
||||
< .withInput({ awesome: "&'\\<>" })
|
||||
< .withMessage("expressions with 3 handlebars aren't escaped")
|
||||
< .toCompileTo("&'\\<>");
|
||||
---
|
||||
> it('escaping expressions', () => {
|
||||
> expectTemplate('{{{awesome}}}').withInput({ awesome: "&'\\<>" }).toCompileTo("&'\\<>");
|
||||
225,228c165
|
||||
< expectTemplate('{{&awesome}}')
|
||||
< .withInput({ awesome: "&'\\<>" })
|
||||
< .withMessage("expressions with {{& handlebars aren't escaped")
|
||||
< .toCompileTo("&'\\<>");
|
||||
---
|
||||
> it('escaping expressions', () => {
|
||||
> expectTemplate('{{{awesome}}}').withInput({ awesome: "&'\\<>" }).toCompileTo("&'\\<>");
|
||||
>
|
||||
> expectTemplate('{{&awesome}}').withInput({ awesome: "&'\\<>" }).toCompileTo("&'\\<>");
|
||||
232d168
|
||||
< .withMessage('by default expressions should be escaped')
|
||||
|
|
|
@ -420,7 +420,7 @@
|
|||
< equals(run, true);
|
||||
---
|
||||
> expect(run).toEqual(true);
|
||||
406,408c314,321
|
||||
406,408c314,317
|
||||
< describe('registration', function() {
|
||||
< it('unregisters', function() {
|
||||
< handlebarsEnv.decorators = {};
|
||||
|
@ -429,13 +429,13 @@
|
|||
> beforeEach(() => {
|
||||
> global.kbnHandlebarsEnv = Handlebars.create();
|
||||
> });
|
||||
>
|
||||
410c319,323
|
||||
< handlebarsEnv.registerDecorator('foo', function() {
|
||||
---
|
||||
> it('unregisters', () => {
|
||||
> // @ts-expect-error: Cannot assign to 'decorators' because it is a read-only property.
|
||||
> kbnHandlebarsEnv!.decorators = {};
|
||||
410c323
|
||||
< handlebarsEnv.registerDecorator('foo', function() {
|
||||
---
|
||||
>
|
||||
> kbnHandlebarsEnv!.registerDecorator('foo', function () {
|
||||
414,416c327,329
|
||||
< equals(!!handlebarsEnv.decorators.foo, true);
|
||||
|
@ -445,18 +445,18 @@
|
|||
> expect(!!kbnHandlebarsEnv!.decorators.foo).toEqual(true);
|
||||
> kbnHandlebarsEnv!.unregisterDecorator('foo');
|
||||
> expect(kbnHandlebarsEnv!.decorators.foo).toBeUndefined();
|
||||
419,424c332,339
|
||||
419,420c332,334
|
||||
< it('allows multiple globals', function() {
|
||||
< handlebarsEnv.decorators = {};
|
||||
<
|
||||
< handlebarsEnv.registerDecorator({
|
||||
< foo: function() {},
|
||||
< bar: function() {}
|
||||
---
|
||||
> it('allows multiple globals', () => {
|
||||
> // @ts-expect-error: Cannot assign to 'decorators' because it is a read-only property.
|
||||
> kbnHandlebarsEnv!.decorators = {};
|
||||
>
|
||||
422,424c336,339
|
||||
< handlebarsEnv.registerDecorator({
|
||||
< foo: function() {},
|
||||
< bar: function() {}
|
||||
---
|
||||
> // @ts-expect-error: Expected 2 arguments, but got 1.
|
||||
> kbnHandlebarsEnv!.registerDecorator({
|
||||
> foo() {},
|
||||
|
|
|
@ -341,7 +341,7 @@
|
|||
> // TODO: This test has been added to the `4.x` branch of the handlebars.js repo along with a code-fix,
|
||||
> // but a new version of the handlebars package containing this fix has not yet been published to npm.
|
||||
> //
|
||||
> // Before enabling this code, a new version of handlebars needs to be released and the corrosponding
|
||||
> // Before enabling this code, a new version of handlebars needs to be released and the corresponding
|
||||
> // updates needs to be applied to this implementation.
|
||||
> //
|
||||
> // See: https://github.com/handlebars-lang/handlebars.js/commit/30dbf0478109ded8f12bb29832135d480c17e367
|
||||
|
@ -703,20 +703,20 @@
|
|||
---
|
||||
> expect('03').toEqual(levelArg);
|
||||
> expect('whee').toEqual(logArg);
|
||||
609,616c511,521
|
||||
609,610c511,513
|
||||
< it('should output to info', function() {
|
||||
< var called;
|
||||
<
|
||||
---
|
||||
> it('should output to info', function () {
|
||||
> let calls = 0;
|
||||
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
|
||||
612,616c515,521
|
||||
< console.info = function(info) {
|
||||
< equals('whee', info);
|
||||
< called = true;
|
||||
< console.info = $info;
|
||||
< console.log = $log;
|
||||
---
|
||||
> it('should output to info', function () {
|
||||
> let calls = 0;
|
||||
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
|
||||
>
|
||||
> console.info = function (info) {
|
||||
> expect('whee').toEqual(info);
|
||||
> calls++;
|
||||
|
@ -746,19 +746,19 @@
|
|||
---
|
||||
> expectTemplate('{{log blah}}').withInput({ blah: 'whee' }).toCompileTo('');
|
||||
> expect(calls).toEqual(callsExpected);
|
||||
631,637c536,543
|
||||
631,632c536,538
|
||||
< it('should log at data level', function() {
|
||||
< var called;
|
||||
<
|
||||
---
|
||||
> it('should log at data level', function () {
|
||||
> let calls = 0;
|
||||
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
|
||||
634,637c540,543
|
||||
< console.error = function(log) {
|
||||
< equals('whee', log);
|
||||
< called = true;
|
||||
< console.error = $error;
|
||||
---
|
||||
> it('should log at data level', function () {
|
||||
> let calls = 0;
|
||||
> const callsExpected = process.env.AST || process.env.EVAL ? 1 : 2;
|
||||
>
|
||||
> console.error = function (log) {
|
||||
> expect('whee').toEqual(log);
|
||||
> calls++;
|
||||
|
|
|
@ -1,15 +1,24 @@
|
|||
1,92c1,24
|
||||
1,4c1,6
|
||||
< describe('compiler', function() {
|
||||
< if (!Handlebars.compile) {
|
||||
< return;
|
||||
< }
|
||||
<
|
||||
---
|
||||
> /*
|
||||
> * This file is forked from the handlebars project (https://github.com/handlebars-lang/handlebars.js),
|
||||
> * and may include modifications made by Elasticsearch B.V.
|
||||
> * Elasticsearch B.V. licenses this file to you under the MIT License.
|
||||
> * See `packages/kbn-handlebars/LICENSE` for more information.
|
||||
> */
|
||||
6,10c8
|
||||
< describe('#equals', function() {
|
||||
< function compile(string) {
|
||||
< var ast = Handlebars.parse(string);
|
||||
< return new Handlebars.Compiler().compile(ast, {});
|
||||
< }
|
||||
<
|
||||
---
|
||||
> import Handlebars from '../..';
|
||||
12,60c10,13
|
||||
< it('should treat as equal', function() {
|
||||
< equal(compile('foo').equals(compile('foo')), true);
|
||||
< equal(compile('{{foo}}').equals(compile('{{foo}}')), true);
|
||||
|
@ -59,7 +68,12 @@
|
|||
< );
|
||||
< });
|
||||
< });
|
||||
<
|
||||
---
|
||||
> describe('compiler', () => {
|
||||
> const compileFns = ['compile', 'compileAST'];
|
||||
> if (process.env.AST) compileFns.splice(0, 1);
|
||||
> else if (process.env.EVAL) compileFns.splice(1, 1);
|
||||
62,78c15,17
|
||||
< describe('#compile', function() {
|
||||
< it('should fail with invalid input', function() {
|
||||
< shouldThrow(
|
||||
|
@ -77,7 +91,11 @@
|
|||
< 'You must pass a string or Handlebars AST to Handlebars.compile. You passed [object Object]'
|
||||
< );
|
||||
< });
|
||||
<
|
||||
---
|
||||
> compileFns.forEach((compileName) => {
|
||||
> // @ts-expect-error
|
||||
> const compile = Handlebars[compileName];
|
||||
80,92c19,24
|
||||
< it('should include the location in the error (row and column)', function() {
|
||||
< try {
|
||||
< Handlebars.compile(' \n {{#if}}\n{{/def}}')();
|
||||
|
@ -92,24 +110,6 @@
|
|||
< "if doesn't match def - 2:5",
|
||||
< 'Checking error message'
|
||||
---
|
||||
> /*
|
||||
> * This file is forked from the handlebars project (https://github.com/handlebars-lang/handlebars.js),
|
||||
> * and may include modifications made by Elasticsearch B.V.
|
||||
> * Elasticsearch B.V. licenses this file to you under the MIT License.
|
||||
> * See `packages/kbn-handlebars/LICENSE` for more information.
|
||||
> */
|
||||
>
|
||||
> import Handlebars from '../..';
|
||||
>
|
||||
> describe('compiler', () => {
|
||||
> const compileFns = ['compile', 'compileAST'];
|
||||
> if (process.env.AST) compileFns.splice(0, 1);
|
||||
> else if (process.env.EVAL) compileFns.splice(1, 1);
|
||||
>
|
||||
> compileFns.forEach((compileName) => {
|
||||
> // @ts-expect-error
|
||||
> const compile = Handlebars[compileName];
|
||||
>
|
||||
> describe(`#${compileName}`, () => {
|
||||
> it('should fail with invalid input', () => {
|
||||
> expect(function () {
|
||||
|
@ -160,29 +160,10 @@
|
|||
< });
|
||||
---
|
||||
> });
|
||||
131,152c34,48
|
||||
131,133c34,48
|
||||
< it('can pass through an empty string', function() {
|
||||
< equal(Handlebars.compile('')(), '');
|
||||
< });
|
||||
<
|
||||
< it('should not modify the options.data property(GH-1327)', function() {
|
||||
< var options = { data: [{ a: 'foo' }, { a: 'bar' }] };
|
||||
< Handlebars.compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)();
|
||||
< equal(
|
||||
< JSON.stringify(options, 0, 2),
|
||||
< JSON.stringify({ data: [{ a: 'foo' }, { a: 'bar' }] }, 0, 2)
|
||||
< );
|
||||
< });
|
||||
<
|
||||
< it('should not modify the options.knownHelpers property(GH-1327)', function() {
|
||||
< var options = { knownHelpers: {} };
|
||||
< Handlebars.compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)();
|
||||
< equal(
|
||||
< JSON.stringify(options, 0, 2),
|
||||
< JSON.stringify({ knownHelpers: {} }, 0, 2)
|
||||
< );
|
||||
< });
|
||||
< });
|
||||
---
|
||||
> it('should include the location in the error (row and column)', () => {
|
||||
> try {
|
||||
|
@ -199,7 +180,44 @@
|
|||
> expect(err.lineNumber).toEqual(2);
|
||||
> }
|
||||
> });
|
||||
154,170c50,57
|
||||
135,142c50,57
|
||||
< it('should not modify the options.data property(GH-1327)', function() {
|
||||
< var options = { data: [{ a: 'foo' }, { a: 'bar' }] };
|
||||
< Handlebars.compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)();
|
||||
< equal(
|
||||
< JSON.stringify(options, 0, 2),
|
||||
< JSON.stringify({ data: [{ a: 'foo' }, { a: 'bar' }] }, 0, 2)
|
||||
< );
|
||||
< });
|
||||
---
|
||||
> it('should include the location as enumerable property', () => {
|
||||
> try {
|
||||
> compile(' \n {{#if}}\n{{/def}}')({});
|
||||
> expect(true).toEqual(false);
|
||||
> } catch (err) {
|
||||
> expect(Object.prototype.propertyIsEnumerable.call(err, 'column')).toEqual(true);
|
||||
> }
|
||||
> });
|
||||
144,152c59,66
|
||||
< it('should not modify the options.knownHelpers property(GH-1327)', function() {
|
||||
< var options = { knownHelpers: {} };
|
||||
< Handlebars.compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)();
|
||||
< equal(
|
||||
< JSON.stringify(options, 0, 2),
|
||||
< JSON.stringify({ knownHelpers: {} }, 0, 2)
|
||||
< );
|
||||
< });
|
||||
< });
|
||||
---
|
||||
> it('can utilize AST instance', () => {
|
||||
> expect(
|
||||
> compile({
|
||||
> type: 'Program',
|
||||
> body: [{ type: 'ContentStatement', value: 'Hello' }],
|
||||
> })({})
|
||||
> ).toEqual('Hello');
|
||||
> });
|
||||
154,170c68,70
|
||||
< describe('#precompile', function() {
|
||||
< it('should fail with invalid input', function() {
|
||||
< shouldThrow(
|
||||
|
@ -218,24 +236,15 @@
|
|||
< );
|
||||
< });
|
||||
---
|
||||
> it('should include the location as enumerable property', () => {
|
||||
> try {
|
||||
> compile(' \n {{#if}}\n{{/def}}')({});
|
||||
> expect(true).toEqual(false);
|
||||
> } catch (err) {
|
||||
> expect(Object.prototype.propertyIsEnumerable.call(err, 'column')).toEqual(true);
|
||||
> }
|
||||
> it('can pass through an empty string', () => {
|
||||
> expect(compile('')({})).toEqual('');
|
||||
> });
|
||||
172,175c59,61
|
||||
172,182c72,78
|
||||
< it('can utilize AST instance', function() {
|
||||
< equal(
|
||||
< /return "Hello"/.test(
|
||||
< Handlebars.precompile({
|
||||
---
|
||||
> it('can utilize AST instance', () => {
|
||||
> expect(
|
||||
> compile({
|
||||
177,182c63,78
|
||||
< type: 'Program',
|
||||
< body: [{ type: 'ContentStatement', value: 'Hello' }]
|
||||
< })
|
||||
< ),
|
||||
|
@ -243,15 +252,6 @@
|
|||
< );
|
||||
< });
|
||||
---
|
||||
> body: [{ type: 'ContentStatement', value: 'Hello' }],
|
||||
> })({})
|
||||
> ).toEqual('Hello');
|
||||
> });
|
||||
>
|
||||
> it('can pass through an empty string', () => {
|
||||
> expect(compile('')({})).toEqual('');
|
||||
> });
|
||||
>
|
||||
> it('should not modify the options.data property(GH-1327)', () => {
|
||||
> const options = { data: [{ a: 'foo' }, { a: 'bar' }] };
|
||||
> compile('{{#each data}}{{@index}}:{{a}} {{/each}}', options)({});
|
||||
|
|
|
@ -306,21 +306,22 @@
|
|||
> helper: () => 'winning',
|
||||
293a271
|
||||
> // @ts-expect-error
|
||||
295,298c273,275
|
||||
295,299d272
|
||||
< var helpers = {
|
||||
< './helper': function() {
|
||||
< return 'fail';
|
||||
< }
|
||||
---
|
||||
>
|
||||
> const helpers = {
|
||||
> './helper': () => 'fail',
|
||||
301,309c278,279
|
||||
< };
|
||||
301,304c274,276
|
||||
< expectTemplate('{{./helper 1}}')
|
||||
< .withInput(hash)
|
||||
< .withHelpers(helpers)
|
||||
< .toCompileTo('winning');
|
||||
<
|
||||
---
|
||||
> const helpers = {
|
||||
> './helper': () => 'fail',
|
||||
> };
|
||||
306,309c278,279
|
||||
< expectTemplate('{{hash/helper 1}}')
|
||||
< .withInput(hash)
|
||||
< .withHelpers(helpers)
|
||||
|
@ -431,19 +432,19 @@
|
|||
> expect(kbnHandlebarsEnv!.helpers.foo).toBeDefined();
|
||||
> kbnHandlebarsEnv!.unregisterHelper('foo');
|
||||
> expect(kbnHandlebarsEnv!.helpers.foo).toBeUndefined();
|
||||
398,404c362,368
|
||||
398,400c362,364
|
||||
< it('allows multiple globals', function() {
|
||||
< var helpers = handlebarsEnv.helpers;
|
||||
< handlebarsEnv.helpers = {};
|
||||
<
|
||||
< handlebarsEnv.registerHelper({
|
||||
< if: helpers['if'],
|
||||
< world: function() {
|
||||
---
|
||||
> it('allows multiple globals', () => {
|
||||
> const ifHelper = kbnHandlebarsEnv!.helpers.if;
|
||||
> deleteAllKeys(kbnHandlebarsEnv!.helpers);
|
||||
>
|
||||
402,404c366,368
|
||||
< handlebarsEnv.registerHelper({
|
||||
< if: helpers['if'],
|
||||
< world: function() {
|
||||
---
|
||||
> kbnHandlebarsEnv!.registerHelper({
|
||||
> if: ifHelper,
|
||||
> world() {
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
1,10c1,15
|
||||
1,6c1,6
|
||||
< describe('security issues', function() {
|
||||
< describe('GH-1495: Prevent Remote Code Execution via constructor', function() {
|
||||
< it('should not allow constructors to be accessed', function() {
|
||||
< expectTemplate('{{lookup (lookup this "constructor") "name"}}')
|
||||
< .withInput({})
|
||||
< .toCompileTo('');
|
||||
<
|
||||
< expectTemplate('{{constructor.name}}')
|
||||
< .withInput({})
|
||||
< .toCompileTo('');
|
||||
---
|
||||
> /*
|
||||
> * This file is forked from the handlebars project (https://github.com/handlebars-lang/handlebars.js),
|
||||
|
@ -16,7 +12,11 @@
|
|||
> * Elasticsearch B.V. licenses this file to you under the MIT License.
|
||||
> * See `packages/kbn-handlebars/LICENSE` for more information.
|
||||
> */
|
||||
>
|
||||
8,10c8,15
|
||||
< expectTemplate('{{constructor.name}}')
|
||||
< .withInput({})
|
||||
< .toCompileTo('');
|
||||
---
|
||||
> import Handlebars from '../..';
|
||||
> import { expectTemplate } from '../__jest__/test_bench';
|
||||
>
|
||||
|
@ -150,7 +150,7 @@
|
|||
< '{{lookup this "__proto__"}}'
|
||||
---
|
||||
> '{{lookup this "__proto__"}}',
|
||||
144,257c111,114
|
||||
144,382c111,114
|
||||
< templates.forEach(function(template) {
|
||||
< describe('access should be denied to ' + template, function() {
|
||||
< it('by default', function() {
|
||||
|
@ -265,12 +265,7 @@
|
|||
< .toCompileTo('');
|
||||
<
|
||||
< expect(spy.callCount).to.equal(0);
|
||||
---
|
||||
> templates.forEach((template) => {
|
||||
> describe('access should be denied to ' + template, () => {
|
||||
> it('by default', () => {
|
||||
> expectTemplate(template).withInput({}).toCompileTo('');
|
||||
259,399d115
|
||||
< });
|
||||
<
|
||||
< it('can be turned off, if turned on by default', function() {
|
||||
< expectTemplate('{{aMethod}}')
|
||||
|
@ -395,8 +390,12 @@
|
|||
< sinon.replace(handlebarsEnv, 'template', function(templateSpec) {
|
||||
< templateSpec.main = wrapToAdjustContainer(templateSpec.main);
|
||||
< return oldTemplateMethod.call(this, templateSpec);
|
||||
< });
|
||||
< });
|
||||
---
|
||||
> templates.forEach((template) => {
|
||||
> describe('access should be denied to ' + template, () => {
|
||||
> it('by default', () => {
|
||||
> expectTemplate(template).withInput({}).toCompileTo('');
|
||||
385,400d116
|
||||
<
|
||||
< afterEach(function() {
|
||||
< sinon.restore();
|
||||
|
@ -412,6 +411,7 @@
|
|||
< expectTemplate('{{anArray.length}}')
|
||||
< .withInput({ anArray: ['a', 'b', 'c'] })
|
||||
< .toCompileTo('3');
|
||||
< });
|
||||
404,409c120,122
|
||||
< describe('escapes template variables', function() {
|
||||
< it('in compat mode', function() {
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
1,5c1,12
|
||||
1c1,6
|
||||
< var Exception = Handlebars.Exception;
|
||||
<
|
||||
< describe('strict', function() {
|
||||
< describe('strict mode', function() {
|
||||
< it('should error on missing property lookup', function() {
|
||||
---
|
||||
> /*
|
||||
> * This file is forked from the handlebars project (https://github.com/handlebars-lang/handlebars.js),
|
||||
|
@ -11,7 +7,11 @@
|
|||
> * Elasticsearch B.V. licenses this file to you under the MIT License.
|
||||
> * See `packages/kbn-handlebars/LICENSE` for more information.
|
||||
> */
|
||||
>
|
||||
3,5c8,12
|
||||
< describe('strict', function() {
|
||||
< describe('strict mode', function() {
|
||||
< it('should error on missing property lookup', function() {
|
||||
---
|
||||
> import { expectTemplate } from '../__jest__/test_bench';
|
||||
>
|
||||
> describe('strict', () => {
|
||||
|
|
|
@ -214,7 +214,7 @@
|
|||
< t: function(defaultString) {
|
||||
---
|
||||
> t(defaultString) {
|
||||
186,212d181
|
||||
186,242d181
|
||||
< }
|
||||
< })
|
||||
< .toCompileTo('<input aria-label="Name" placeholder="Example User" />');
|
||||
|
@ -242,7 +242,7 @@
|
|||
< 'string params for outer helper processed correctly'
|
||||
< );
|
||||
< return a + b;
|
||||
214,231d182
|
||||
< },
|
||||
<
|
||||
< blorg: function(a, options) {
|
||||
< equals(
|
||||
|
@ -261,7 +261,7 @@
|
|||
< .withInput({
|
||||
< foo: {},
|
||||
< yeah: {}
|
||||
233,248c184
|
||||
< })
|
||||
< .toCompileTo('fooyeah');
|
||||
< });
|
||||
<
|
||||
|
@ -272,11 +272,11 @@
|
|||
< blog: function(options) {
|
||||
< equals(options.hashTypes.fun, 'SubExpression');
|
||||
< return 'val is ' + options.hash.fun;
|
||||
< },
|
||||
244,246d182
|
||||
< bork: function() {
|
||||
< return 'BORK';
|
||||
< }
|
||||
< })
|
||||
248c184
|
||||
< .toCompileTo('val is BORK');
|
||||
---
|
||||
> .toCompileTo('<input aria-label="Name" placeholder="Example User" />');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
1,86c1,21
|
||||
1,55c1,6
|
||||
< describe('utils', function() {
|
||||
< describe('#SafeString', function() {
|
||||
< it('constructing a safestring from a string and checking its type', function() {
|
||||
|
@ -54,7 +54,14 @@
|
|||
< equals(Handlebars.Utils.escapeExpression([]), [].toString());
|
||||
< });
|
||||
< });
|
||||
<
|
||||
---
|
||||
> /*
|
||||
> * This file is forked from the handlebars project (https://github.com/handlebars-lang/handlebars.js),
|
||||
> * and may include modifications made by Elasticsearch B.V.
|
||||
> * Elasticsearch B.V. licenses this file to you under the MIT License.
|
||||
> * See `packages/kbn-handlebars/LICENSE` for more information.
|
||||
> */
|
||||
57,64c8,9
|
||||
< describe('#isEmpty', function() {
|
||||
< it('should not be empty', function() {
|
||||
< equals(Handlebars.Utils.isEmpty(undefined), true);
|
||||
|
@ -63,13 +70,23 @@
|
|||
< equals(Handlebars.Utils.isEmpty(''), true);
|
||||
< equals(Handlebars.Utils.isEmpty([]), true);
|
||||
< });
|
||||
<
|
||||
---
|
||||
> import Handlebars from '../..';
|
||||
> import { expectTemplate } from '../__jest__/test_bench';
|
||||
66,70c11,16
|
||||
< it('should be empty', function() {
|
||||
< equals(Handlebars.Utils.isEmpty(0), false);
|
||||
< equals(Handlebars.Utils.isEmpty([1]), false);
|
||||
< equals(Handlebars.Utils.isEmpty('foo'), false);
|
||||
< equals(Handlebars.Utils.isEmpty({ bar: 1 }), false);
|
||||
< });
|
||||
---
|
||||
> describe('utils', function () {
|
||||
> describe('#SafeString', function () {
|
||||
> it('constructing a safestring from a string and checking its type', function () {
|
||||
> const safe = new Handlebars.SafeString('testing 1, 2, 3');
|
||||
> expect(safe).toBeInstanceOf(Handlebars.SafeString);
|
||||
> expect(safe.toString()).toEqual('testing 1, 2, 3');
|
||||
72,83d17
|
||||
< });
|
||||
<
|
||||
< describe('#extend', function() {
|
||||
|
@ -82,28 +99,10 @@
|
|||
< var b = { b: 2 };
|
||||
<
|
||||
< Handlebars.Utils.extend(b, new A());
|
||||
<
|
||||
85,86c19,21
|
||||
< equals(b.a, 1);
|
||||
< equals(b.b, 2);
|
||||
---
|
||||
> /*
|
||||
> * This file is forked from the handlebars project (https://github.com/handlebars-lang/handlebars.js),
|
||||
> * and may include modifications made by Elasticsearch B.V.
|
||||
> * Elasticsearch B.V. licenses this file to you under the MIT License.
|
||||
> * See `packages/kbn-handlebars/LICENSE` for more information.
|
||||
> */
|
||||
>
|
||||
> import Handlebars from '../..';
|
||||
> import { expectTemplate } from '../__jest__/test_bench';
|
||||
>
|
||||
> describe('utils', function () {
|
||||
> describe('#SafeString', function () {
|
||||
> it('constructing a safestring from a string and checking its type', function () {
|
||||
> const safe = new Handlebars.SafeString('testing 1, 2, 3');
|
||||
> expect(safe).toBeInstanceOf(Handlebars.SafeString);
|
||||
> expect(safe.toString()).toEqual('testing 1, 2, 3');
|
||||
> });
|
||||
>
|
||||
> it('it should not escape SafeString properties', function () {
|
||||
> const name = new Handlebars.SafeString('<em>Sean O'Malley</em>');
|
||||
> expectTemplate('{{name}}').withInput({ name }).toCompileTo('<em>Sean O'Malley</em>');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
1,24c1,17
|
||||
1,19c1,6
|
||||
< describe('whitespace control', function() {
|
||||
< it('should strip whitespace around mustache calls', function() {
|
||||
< var hash = { foo: 'bar<' };
|
||||
|
@ -18,11 +18,6 @@
|
|||
< expectTemplate(' {{~&foo~}} ')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo('bar<');
|
||||
<
|
||||
< expectTemplate(' {{~{foo}~}} ')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo('bar<');
|
||||
<
|
||||
---
|
||||
> /*
|
||||
> * This file is forked from the handlebars project (https://github.com/handlebars-lang/handlebars.js),
|
||||
|
@ -30,9 +25,13 @@
|
|||
> * Elasticsearch B.V. licenses this file to you under the MIT License.
|
||||
> * See `packages/kbn-handlebars/LICENSE` for more information.
|
||||
> */
|
||||
>
|
||||
21,23c8
|
||||
< expectTemplate(' {{~{foo}~}} ')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo('bar<');
|
||||
---
|
||||
> import { expectTemplate } from '../__jest__/test_bench';
|
||||
>
|
||||
24a10,17
|
||||
> describe('whitespace control', () => {
|
||||
> it('should strip whitespace around mustache calls', () => {
|
||||
> const hash = { foo: 'bar<' };
|
||||
|
@ -41,7 +40,7 @@
|
|||
> expectTemplate(' {{foo~}} ').withInput(hash).toCompileTo(' bar<');
|
||||
> expectTemplate(' {{~&foo~}} ').withInput(hash).toCompileTo('bar<');
|
||||
> expectTemplate(' {{~{foo}~}} ').withInput(hash).toCompileTo('bar<');
|
||||
28,46c21,28
|
||||
28,42c21,23
|
||||
< describe('blocks', function() {
|
||||
< it('should strip whitespace around simple block calls', function() {
|
||||
< var hash = { foo: 'bar<' };
|
||||
|
@ -57,15 +56,15 @@
|
|||
< expectTemplate(' {{~#if foo}} bar {{~/if}} ')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo(' bar ');
|
||||
<
|
||||
< expectTemplate(' {{#if foo}} bar {{/if}} ')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo(' bar ');
|
||||
---
|
||||
> describe('blocks', () => {
|
||||
> it('should strip whitespace around simple block calls', () => {
|
||||
> const hash = { foo: 'bar<' };
|
||||
>
|
||||
44,46c25,28
|
||||
< expectTemplate(' {{#if foo}} bar {{/if}} ')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo(' bar ');
|
||||
---
|
||||
> expectTemplate(' {{~#if foo~}} bar {{~/if~}} ').withInput(hash).toCompileTo('bar');
|
||||
> expectTemplate(' {{#if foo~}} bar {{/if~}} ').withInput(hash).toCompileTo(' bar ');
|
||||
> expectTemplate(' {{~#if foo}} bar {{~/if}} ').withInput(hash).toCompileTo(' bar ');
|
||||
|
@ -87,7 +86,7 @@
|
|||
< ).toCompileTo('bar');
|
||||
---
|
||||
> expectTemplate(' \n\n{{~^if foo~}} \n\nbar \n\n{{~/if~}}\n\n ').toCompileTo('bar');
|
||||
71,80c47,48
|
||||
71,88c47,48
|
||||
< it('should strip whitespace around complex block calls', function() {
|
||||
< var hash = { foo: 'bar<' };
|
||||
<
|
||||
|
@ -98,34 +97,34 @@
|
|||
< expectTemplate('{{#if foo~}} bar {{^~}} baz {{/if}}')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo('bar ');
|
||||
---
|
||||
> it('should strip whitespace around complex block calls', () => {
|
||||
> const hash = { foo: 'bar<' };
|
||||
82,84c50,54
|
||||
<
|
||||
< expectTemplate('{{#if foo}} bar {{~^~}} baz {{~/if}}')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo(' bar');
|
||||
<
|
||||
< expectTemplate('{{#if foo}} bar {{^~}} baz {{/if}}')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo(' bar ');
|
||||
---
|
||||
> it('should strip whitespace around complex block calls', () => {
|
||||
> const hash = { foo: 'bar<' };
|
||||
90,92c50,54
|
||||
< expectTemplate('{{#if foo~}} bar {{~else~}} baz {{~/if}}')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo('bar');
|
||||
---
|
||||
> expectTemplate('{{#if foo~}} bar {{~^~}} baz {{~/if}}').withInput(hash).toCompileTo('bar');
|
||||
> expectTemplate('{{#if foo~}} bar {{^~}} baz {{/if}}').withInput(hash).toCompileTo('bar ');
|
||||
> expectTemplate('{{#if foo}} bar {{~^~}} baz {{~/if}}').withInput(hash).toCompileTo(' bar');
|
||||
> expectTemplate('{{#if foo}} bar {{^~}} baz {{/if}}').withInput(hash).toCompileTo(' bar ');
|
||||
> expectTemplate('{{#if foo~}} bar {{~else~}} baz {{~/if}}').withInput(hash).toCompileTo('bar');
|
||||
86,90c56
|
||||
< expectTemplate('{{#if foo}} bar {{^~}} baz {{/if}}')
|
||||
< .withInput(hash)
|
||||
< .toCompileTo(' bar ');
|
||||
<
|
||||
< expectTemplate('{{#if foo~}} bar {{~else~}} baz {{~/if}}')
|
||||
---
|
||||
> expectTemplate('\n\n{{~#if foo~}} \n\nbar \n\n{{~^~}} \n\nbaz \n\n{{~/if~}}\n\n')
|
||||
94,102c60
|
||||
94,96c56
|
||||
< expectTemplate(
|
||||
< '\n\n{{~#if foo~}} \n\nbar \n\n{{~^~}} \n\nbaz \n\n{{~/if~}}\n\n'
|
||||
< )
|
||||
< .withInput(hash)
|
||||
< .toCompileTo('bar');
|
||||
<
|
||||
---
|
||||
> expectTemplate('\n\n{{~#if foo~}} \n\nbar \n\n{{~^~}} \n\nbaz \n\n{{~/if~}}\n\n')
|
||||
100,102c60
|
||||
< expectTemplate(
|
||||
< '\n\n{{~#if foo~}} \n\n{{{foo}}} \n\n{{~^~}} \n\nbaz \n\n{{~/if~}}\n\n'
|
||||
< )
|
||||
|
|
|
@ -1,10 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
rm -fr .tmp
|
||||
mkdir .tmp
|
||||
TMP=.tmp-handlebars
|
||||
|
||||
# Try to detect Windows environment (I've not tested this!)
|
||||
if [[ "$OSTYPE" == "msys" ]]; then
|
||||
# Windows environment
|
||||
DEVNULL=NUL
|
||||
else
|
||||
# Everything else (including Cygwin on Windows)
|
||||
DEVNULL=/dev/null
|
||||
fi
|
||||
|
||||
function cleanup {
|
||||
rm -fr $TMP
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
rm -fr $TMP
|
||||
mkdir $TMP
|
||||
|
||||
echo "Cloning handlebars repo..."
|
||||
git clone -q --depth 1 https://github.com/handlebars-lang/handlebars.js.git -b 4.x .tmp/handlebars
|
||||
git clone -q --depth 1 https://github.com/handlebars-lang/handlebars.js.git -b 4.x $TMP/handlebars
|
||||
|
||||
files=(packages/kbn-handlebars/src/upstream/index.*.test.ts)
|
||||
|
||||
|
@ -16,18 +35,54 @@ do
|
|||
echo "Checking for changes to spec/$file.js..."
|
||||
|
||||
set +e
|
||||
diff .tmp/handlebars/spec/$file.js packages/kbn-handlebars/src/upstream/index.$file.test.ts > .tmp/$file.patch
|
||||
diff -d --strip-trailing-cr $TMP/handlebars/spec/$file.js packages/kbn-handlebars/src/upstream/index.$file.test.ts > $TMP/$file.patch
|
||||
error=$?
|
||||
set -e
|
||||
if [ $error -gt 1 ]
|
||||
then
|
||||
echo "Error executing diff!"
|
||||
echo "The diff command encountered an unexpected error!"
|
||||
exit $error
|
||||
fi
|
||||
|
||||
diff -u .tmp/$file.patch packages/kbn-handlebars/.patches/$file.patch
|
||||
set +e
|
||||
diff -d --strip-trailing-cr $TMP/$file.patch packages/kbn-handlebars/.patches/$file.patch > $DEVNULL
|
||||
error=$?
|
||||
set -e
|
||||
if [ $error -gt 1 ]
|
||||
then
|
||||
echo "The diff command encountered an unexpected error!"
|
||||
exit $error
|
||||
elif [ $error -gt 0 ]
|
||||
then
|
||||
echo
|
||||
echo "The following files contain unexpected differences:"
|
||||
echo
|
||||
echo " Upstream: spec/$file.js"
|
||||
echo " Downstream: packages/kbn-handlebars/src/upstream/index.$file.test.ts"
|
||||
echo
|
||||
echo "This can happen if either the upstream or the downstream version has been"
|
||||
echo "updated without our patch files being kept up to date."
|
||||
echo
|
||||
echo "To resolve this issue, do the following:"
|
||||
echo
|
||||
echo " 1. Check the '4.x' branch of the upstream git repository to see if the file"
|
||||
echo " has been updated. If so, please ensure that our copy of the file is kept in"
|
||||
echo " sync. You can view the recent upstream commits to this file here:"
|
||||
echo
|
||||
echo " https://github.com/handlebars-lang/handlebars.js/commits/4.x/spec/$file.js"
|
||||
echo
|
||||
echo " 2. Update our patch files by running the following script. This is also"
|
||||
echo " necessary even if it's only the downstream file that has been updated:"
|
||||
echo
|
||||
echo " ./packages/kbn-handlebars/scripts/update_test_patches.sh $file"
|
||||
echo
|
||||
echo " 3. Commit the changes to the updated patch file and execute this script again"
|
||||
echo " until everything passes:"
|
||||
echo
|
||||
echo " ./packages/kbn-handlebars/scripts/check_for_test_changes.sh"
|
||||
echo
|
||||
exit $error
|
||||
fi
|
||||
done
|
||||
|
||||
echo "No changes found :)"
|
||||
|
||||
rm -fr .tmp
|
|
@ -1,12 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
rm -fr .tmp
|
||||
mkdir .tmp
|
||||
TMP=.tmp-handlebars
|
||||
|
||||
function cleanup {
|
||||
rm -fr $TMP
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
rm -fr $TMP
|
||||
mkdir $TMP
|
||||
|
||||
echo "Cloning handlebars repo..."
|
||||
git clone -q --depth 1 https://github.com/handlebars-lang/handlebars.js.git -b 4.x .tmp/handlebars
|
||||
git clone -q --depth 1 https://github.com/handlebars-lang/handlebars.js.git -b 4.x $TMP/handlebars
|
||||
|
||||
files=(packages/kbn-handlebars/src/upstream/index.*.test.ts)
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
# No argument given: Update all patch files
|
||||
files=(packages/kbn-handlebars/src/upstream/index.*.test.ts)
|
||||
else
|
||||
# Argument detected: Update only the requested patch file
|
||||
files=(packages/kbn-handlebars/src/upstream/index.$1.test.ts)
|
||||
fi
|
||||
|
||||
for file in "${files[@]}"
|
||||
do
|
||||
|
@ -15,10 +32,8 @@ do
|
|||
|
||||
echo "Overwriting stored patch file for spec/$file.js..."
|
||||
set +e
|
||||
diff .tmp/handlebars/spec/$file.js packages/kbn-handlebars/src/upstream/index.$file.test.ts > packages/kbn-handlebars/.patches/$file.patch
|
||||
diff -d --strip-trailing-cr $TMP/handlebars/spec/$file.js packages/kbn-handlebars/src/upstream/index.$file.test.ts > packages/kbn-handlebars/.patches/$file.patch
|
||||
set -e
|
||||
done
|
||||
|
||||
echo "All patches updated :)"
|
||||
|
||||
rm -fr .tmp
|
Loading…
Add table
Add a link
Reference in a new issue