From 186e488ace803886f25059b0a866bba82f106b45 Mon Sep 17 00:00:00 2001 From: Demitri Swan Date: Thu, 24 Jan 2019 04:57:11 +0000 Subject: [PATCH] Bug Fix #14961 --- .../features/templating/specs/template_srv.test.ts | 11 +++++++++++ public/app/features/templating/template_srv.ts | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/public/app/features/templating/specs/template_srv.test.ts b/public/app/features/templating/specs/template_srv.test.ts index 4288b5f3928..30faffea3be 100644 --- a/public/app/features/templating/specs/template_srv.test.ts +++ b/public/app/features/templating/specs/template_srv.test.ts @@ -469,6 +469,11 @@ describe('templateSrv', () => { name: 'empty_on_init', current: { value: '', text: '' }, }, + { + type: 'custom', + name: 'foo', + current: { value: 'constructor', text: 'constructor' }, + } ]); _templateSrv.setGrafanaVariable('$__auto_interval_interval', '13m'); _templateSrv.updateTemplateData(); @@ -483,6 +488,12 @@ describe('templateSrv', () => { const target = _templateSrv.replaceWithText('Hello $empty_on_init'); expect(target).toBe('Hello '); }); + + it('should not return a string representation of a constructor property', () => { + const target = _templateSrv.replaceWithText('$foo'); + expect(target).not.toBe('function Object() { [native code] }'); + expect(target).toBe('constructor'); + }); }); describe('built in interval variables', () => { diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index 07656924c9c..2f8068137e5 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -254,7 +254,9 @@ export class TemplateSrv { return match; } - return this.grafanaVariables[variable.current.value] || variable.current.text; + const value = this.grafanaVariables[variable.current.value]; + + return typeof(value) === 'string' ? value : variable.current.text; }); }