[v11.0.x] InfluxDB: Fix interpolation for floating point number values (#86495)

InfluxDB: Fix interpolation for floating point number values (#86396)

return number as it is

(cherry picked from commit 635d85db7a)

Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-04-18 12:20:57 +02:00
committed by GitHub
co-authored by ismail simsek
parent f1c20f8692
commit 8127ea54b6
2 changed files with 23 additions and 0 deletions
@@ -508,6 +508,22 @@ describe('InfluxDataSource Frontend Mode', () => {
const expectation = `(\\/special\\/path|\\/some\\/other\\/path)`;
expect(result).toBe(expectation);
});
it('should return floating point number as it is', () => {
const variableMock = queryBuilder()
.withId('tempVar')
.withName('tempVar')
.withMulti(false)
.withOptions({
text: `1.0`,
value: `1.0`,
})
.build();
const value = `1.0`;
const result = ds.interpolateQueryExpr(value, variableMock, `select value / $tempVar from /^measurement$/`);
const expectation = `1.0`;
expect(result).toBe(expectation);
});
});
});
});
@@ -315,6 +315,13 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
return value;
}
if (typeof value === 'string') {
// Check the value is a number. If not run to escape special characters
if (!isNaN(parseFloat(value))) {
return value;
}
}
// If template variable is a multi-value variable
// we always want to deal with special chars.
if (variable.multi) {