Fix timelion vis escapes single quotes (#84196)
* Remove string escaping * Add unit test
This commit is contained in:
parent
d80e8ca2ee
commit
b312c91010
|
@ -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",
|
||||
}
|
||||
`;
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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]);
|
||||
|
|
Loading…
Reference in a new issue