Skip to content

Commit

Permalink
Merge pull request #1038 from OpenNMS/jira/OPG-488-perf-query-variabl…
Browse files Browse the repository at this point in the history
…e-interpolation-issue

OPG-488: Fix issue with Performance query variable interpolation
  • Loading branch information
synqotik authored Dec 12, 2024
2 parents 233c30d + 0e3ae0b commit a6294dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/datasources/perf-ds/queries/interpolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit a6294dd

Please sign in to comment.