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

return number as it is
This commit is contained in:
ismail simsek 2024-04-18 11:21:41 +02:00 committed by GitHub
parent f3fd2de9dd
commit 635d85db7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -508,6 +508,22 @@ describe('InfluxDataSource Frontend Mode', () => {
const expectation = `(\\/special\\/path|\\/some\\/other\\/path)`; const expectation = `(\\/special\\/path|\\/some\\/other\\/path)`;
expect(result).toBe(expectation); 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);
});
}); });
}); });
}); });

View File

@ -315,6 +315,13 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
return value; 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 // If template variable is a multi-value variable
// we always want to deal with special chars. // we always want to deal with special chars.
if (variable.multi) { if (variable.multi) {