Skip to content

Commit

Permalink
[Canvas] Fixes Error 500 on the workpad update. (#111683)
Browse files Browse the repository at this point in the history
* Fixed bug with treating null argument as the expression function.

* Added a test for checking if a null argument is processeded correctly.

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
Kuznietsov and kibanamachine authored Sep 16, 2021
1 parent e4dc455 commit dbcc75b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/plugins/expressions/common/executor/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ describe('Executor', () => {
types: ['string'],
help: 'other arg',
},
nullable: {
types: ['string', 'null'],
help: 'nullable arg',
default: null,
},
},
extract: (state: ExpressionAstFunction['arguments']) => {
const references: SavedObjectReference[] = [
Expand Down Expand Up @@ -254,6 +259,14 @@ describe('Executor', () => {

expect(formatExpression(executor.inject(state, references))).toBe(expression);
});

test('allows expression function argument to be null', () => {
const expression = `ref nullable=null id="my-id" other={ref id="nested-id" other="other" | foo bar="baz"}`;
const { state, references } = executor.extract(parseExpression(expression));

expect(state.chain[0].arguments.nullable[0]).toBeNull();
expect(formatExpression(executor.inject(state, references))).toBe(expression);
});
});

describe('.getAllMigrations', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/common/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Executor<Context extends Record<string, unknown> = Record<string, u
// if any of arguments are expressions we should migrate those first
link.arguments = mapValues(fnArgs, (asts, argName) => {
return asts.map((arg) => {
if (typeof arg === 'object') {
if (arg && typeof arg === 'object') {
return this.walkAst(arg, action);
}
return arg;
Expand Down

0 comments on commit dbcc75b

Please sign in to comment.