Skip to content

Commit 13dd90b

Browse files
authored
replace function error fix (#87)
1 parent 62ae185 commit 13dd90b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

public/app/features/templating/template_srv.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,13 @@ export class TemplateSrv implements BaseTemplateSrv {
331331
private _replaceWithVariableRegex(text: string, format: string | Function | undefined, replace: ReplaceFunction) {
332332
this.regex.lastIndex = 0;
333333

334-
return text.replace(this.regex, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
335-
const variableName = var1 || var2 || var3;
336-
const fmt = fmt2 || fmt3 || format;
337-
return replace(match, variableName, fieldPath, fmt);
338-
});
334+
return (
335+
text?.replace(this.regex, (match, var1, var2, fmt2, var3, fieldPath, fmt3) => {
336+
const variableName = var1 || var2 || var3;
337+
const fmt = fmt2 || fmt3 || format;
338+
return replace(match, variableName, fieldPath, fmt);
339+
}) || ''
340+
);
339341
}
340342

341343
isAllValue(value: any) {

0 commit comments

Comments
 (0)