Skip to content

Commit

Permalink
[TSVB] fix incomplete string escaping or encoding (#196248)
Browse files Browse the repository at this point in the history
## Summary

Fixes incomplete string escaping or encoding for TSVB.
  • Loading branch information
mbondyra authored Oct 17, 2024
1 parent 3d254c2 commit 7c4a83d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const convertToCumulativeSumColumns = (
// lens supports cumulative sum for count and sum as quick function
// and everything else as formula
if (subFunctionMetric.type !== 'count' && pipelineAgg.name !== 'sum') {
const metaValue = Number(meta?.replace(']', ''));
const metaValue = Number(meta?.replace(/\]/g, ''));
formula = getPipelineSeriesFormula(metric, metrics, subFunctionMetric, {
metaValue,
reducedTimeRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const convertFormulaScriptForPercentileAggs = (
) => {
variables.forEach((variable) => {
const [_, meta] = variable?.field?.split('[') ?? [];
const metaValue = Number(meta?.replace(']', ''));
const metaValue = Number(meta?.replace(/\]/g, ''));
if (!metaValue) {
return;
}
Expand Down Expand Up @@ -163,7 +163,7 @@ export const convertOtherAggsToFormulaColumn = (
const metric = metrics[metrics.length - 1];
const [fieldId, meta] = metric?.field?.split('[') ?? [];
const subFunctionMetric = metrics.find(({ id }) => id === fieldId);
const metaValue = meta ? Number(meta?.replace(']', '')) : undefined;
const metaValue = meta ? Number(meta?.replace(/\]/g, '')) : undefined;

if (!subFunctionMetric) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ const convertMovingAvgOrDerivativeToColumns = (
if (!pipelineAgg) {
return null;
}
const metaValue = Number(meta?.replace(']', ''));
const metaValue = Number(meta?.replace(/\]/g, ''));
const subMetricField = subFunctionMetric.field;
const [nestedFieldId, _] = subMetricField?.split('[') ?? [];
// support nested aggs with formula
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { addAdditionalArgs } from '.';
import { AdditionalArgs } from '../../types';

const escapeQuotes = (str: string) => {
return str?.replace(/'/g, "\\'");
return str?.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
};

const constructFilterRationFormula = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const getFormulaEquivalent = (
}

return getPipelineSeriesFormula(currentMetric, metrics, subFunctionMetric, {
metaValue: nestedMetaValue ? Number(nestedMetaValue?.replace(']', '')) : undefined,
metaValue: nestedMetaValue ? Number(nestedMetaValue?.replace(/\]/g, '')) : undefined,
reducedTimeRange,
timeShift,
});
Expand Down

0 comments on commit 7c4a83d

Please sign in to comment.