[v11.2.x] InfluxDB: Fix variable interpolation in influx db (#93109)

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

Fix variable interpolation in influx db

(cherry picked from commit c0df15dcde)

Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-09-12 17:02:59 +03:00
committed by GitHub
co-authored by Oscar Kilhed
parent 5abb9a8632
commit 62d242b74e
@@ -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);
}