diff --git a/src/plugins/vis_type_timelion/public/__snapshots__/to_ast.test.ts.snap b/src/plugins/vis_type_timelion/public/__snapshots__/to_ast.test.ts.snap index 9e32a6c4ae17c..7635e5214795a 100644 --- a/src/plugins/vis_type_timelion/public/__snapshots__/to_ast.test.ts.snap +++ b/src/plugins/vis_type_timelion/public/__snapshots__/to_ast.test.ts.snap @@ -19,3 +19,23 @@ Object { "type": "expression", } `; + +exports[`timelion vis toExpressionAst function should not escape single quotes 1`] = ` +Object { + "chain": Array [ + Object { + "arguments": Object { + "expression": Array [ + ".es(index=my*,timefield=\\"date\\",split='test field:3',metric='avg:value')", + ], + "interval": Array [ + "auto", + ], + }, + "function": "timelion_vis", + "type": "function", + }, + ], + "type": "expression", +} +`; diff --git a/src/plugins/vis_type_timelion/public/to_ast.test.ts b/src/plugins/vis_type_timelion/public/to_ast.test.ts index 8a9d4b83f94d2..f2030e4b83c19 100644 --- a/src/plugins/vis_type_timelion/public/to_ast.test.ts +++ b/src/plugins/vis_type_timelion/public/to_ast.test.ts @@ -37,4 +37,10 @@ describe('timelion vis toExpressionAst function', () => { const actual = toExpressionAst(vis); expect(actual).toMatchSnapshot(); }); + + it('should not escape single quotes', () => { + vis.params.expression = `.es(index=my*,timefield="date",split='test field:3',metric='avg:value')`; + const actual = toExpressionAst(vis); + expect(actual).toMatchSnapshot(); + }); }); diff --git a/src/plugins/vis_type_timelion/public/to_ast.ts b/src/plugins/vis_type_timelion/public/to_ast.ts index 7044bbf4e5831..535e8e8fe0f77 100644 --- a/src/plugins/vis_type_timelion/public/to_ast.ts +++ b/src/plugins/vis_type_timelion/public/to_ast.ts @@ -21,14 +21,12 @@ import { buildExpression, buildExpressionFunction } from '../../expressions/publ import { Vis } from '../../visualizations/public'; import { TimelionExpressionFunctionDefinition, TimelionVisParams } from './timelion_vis_fn'; -const escapeString = (data: string): string => { - return data.replace(/\\/g, `\\\\`).replace(/'/g, `\\'`); -}; - export const toExpressionAst = (vis: Vis) => { + const { expression, interval } = vis.params; + const timelion = buildExpressionFunction('timelion_vis', { - expression: escapeString(vis.params.expression), - interval: escapeString(vis.params.interval), + expression, + interval, }); const ast = buildExpression([timelion]);