Merge pull request #15018 from miroswan/14961-constructor-as-rvalue

Bug Fix #14961
This commit is contained in:
Torkel Ödegaard 2019-01-26 11:11:32 +01:00 committed by GitHub
commit f3dc5381ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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', () => {

View File

@ -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;
});
}