Skip to content

Commit

Permalink
Fix timelion vis escapes single quotes (elastic#84196)
Browse files Browse the repository at this point in the history
* Remove string escaping

* Add unit test
  • Loading branch information
Daniil authored and sulemanof committed Nov 24, 2020
1 parent 2a49925 commit a4fb489
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/plugins/vis_type_timelion/public/to_ast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
10 changes: 4 additions & 6 deletions src/plugins/vis_type_timelion/public/to_ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimelionVisParams>) => {
const { expression, interval } = vis.params;

const timelion = buildExpressionFunction<TimelionExpressionFunctionDefinition>('timelion_vis', {
expression: escapeString(vis.params.expression),
interval: escapeString(vis.params.interval),
expression,
interval,
});

const ast = buildExpression([timelion]);
Expand Down

0 comments on commit a4fb489

Please sign in to comment.