From 0e3ae0b406f4a5e8c4f9d60d308fec3991d3656e Mon Sep 17 00:00:00 2001 From: Scott Theleman Date: Mon, 9 Dec 2024 19:17:02 -0500 Subject: [PATCH] OPG-488: Fix issue with Performance query variable interpolation --- package-lock.json | 2 +- src/datasources/perf-ds/queries/interpolate.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 378c937e..4b17d259 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "opennms-grafana-plugin", - "version": "9.0.14", + "version": "9.0.15-SNAPSHOT", "license": "MIT", "dependencies": { "@emotion/css": "^11.1.3", diff --git a/src/datasources/perf-ds/queries/interpolate.ts b/src/datasources/perf-ds/queries/interpolate.ts index fd165bef..03c9d7da 100644 --- a/src/datasources/perf-ds/queries/interpolate.ts +++ b/src/datasources/perf-ds/queries/interpolate.ts @@ -146,10 +146,14 @@ const replaceQueryValueWithVariables = (queryValue: any, variables: Interpolatio } // check for '$variableName' syntax - const regexVarName = '\\$' + variable.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + // we add word boundary at the end so we don't have spurious partial matches on variables + // having same beginning portion of name + let regexVarName = '\\$' + variable.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + regexVarName = regexVarName + '\\b' + interpolatedValue = interpolatedValue.replace(new RegExp(regexVarName, 'g'), variableValue) - // check for ${var} with optional {$var:format} where 'format' must be alphanumeric + // check for ${var} with optional ${var:format} where 'format' must be alphanumeric const regexWithBracesAndFormat = getVariableWithBracesReferencePattern(variable.name) interpolatedValue = interpolatedValue.replace(new RegExp(regexWithBracesAndFormat, 'g'), variableValue) })