[8.x] [TSVB] fix incomplete string escaping or encoding (#196248) (#196668)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[TSVB] fix incomplete string escaping or encoding
(#196248)](https://github.com/elastic/kibana/pull/196248)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marta
Bondyra","email":"4283304+mbondyra@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-10-17T11:13:09Z","message":"[TSVB]
fix incomplete string escaping or encoding (#196248)\n\n##
Summary\r\n\r\nFixes incomplete string escaping or encoding for
TSVB.","sha":"7c4a83d4c920b5bc35b88ffc0460c139bb0d846b","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:TSVB","release_note:fix","Team:Visualizations","v9.0.0","backport:prev-major","v8.17.0"],"title":"[TSVB]
fix incomplete string escaping or
encoding","number":196248,"url":"https://github.com/elastic/kibana/pull/196248","mergeCommit":{"message":"[TSVB]
fix incomplete string escaping or encoding (#196248)\n\n##
Summary\r\n\r\nFixes incomplete string escaping or encoding for
TSVB.","sha":"7c4a83d4c920b5bc35b88ffc0460c139bb0d846b"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196248","number":196248,"mergeCommit":{"message":"[TSVB]
fix incomplete string escaping or encoding (#196248)\n\n##
Summary\r\n\r\nFixes incomplete string escaping or encoding for
TSVB.","sha":"7c4a83d4c920b5bc35b88ffc0460c139bb0d846b"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Marta Bondyra <4283304+mbondyra@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2024-10-17 23:57:55 +11:00 committed by GitHub
parent bd287d8d05
commit 52f92a837f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 6 additions and 6 deletions

View file

@ -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,

View file

@ -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;
}
@ -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;

View file

@ -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

View file

@ -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 = (

View file

@ -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,
});