InfluxDB: Fix variable interpolation in influx db (#92988)

Fix variable interpolation in influx db
This commit is contained in:
Oscar Kilhed 2024-09-09 15:35:30 +02:00 committed by GitHub
parent 58907a8464
commit c0df15dcde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -324,11 +324,6 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
}
interpolateQueryExpr(value: string | string[] = [], variable: QueryVariableModel, query?: string) {
// If there is no query just return the value directly
if (!query) {
return value;
}
if (typeof value === 'string') {
// Check the value is a number. If not run to escape special characters
if (!isNaN(parseFloat(value))) {
@ -358,7 +353,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
// regex below checks if the variable inside /^...$/ (^ and $ is optional)
// i.e. /^$myVar$/ or /$myVar/ or /^($myVar)$/
const regex = new RegExp(`\\/(?:\\^)?(.*)(\\$${variable.name})(.*)(?:\\$)?\\/`, 'gm');
if (regex.test(query)) {
if (query && regex.test(query)) {
if (typeof value === 'string') {
return escapeRegex(value);
}