Skip to content

Commit 1d7e71c

Browse files
gurinder39GurinderRawala
authored andcommitted
replace function error fix (#87)
1 parent 2b72716 commit 1d7e71c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

public/app/features/templating/template_srv.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,13 @@ export class TemplateSrv implements BaseTemplateSrv {
367367
private _replaceWithVariableRegex(text: string, format: string | Function | undefined, replace: ReplaceFunction) {
368368
this.regex.lastIndex = 0;
369369

370-
return text.replace(this.regex, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
371-
const variableName = var1 || var2 || var3;
372-
const fmt = fmt2 || fmt3 || format;
373-
return replace(match, variableName, fieldPath, fmt);
374-
});
370+
return (
371+
text?.replace(this.regex, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
372+
const variableName = var1 || var2 || var3;
373+
const fmt = fmt2 || fmt3 || format;
374+
return replace(match, variableName, fieldPath, fmt);
375+
}) || ''
376+
);
375377
}
376378

377379
isAllValue(value: unknown) {

0 commit comments

Comments
 (0)