diff --git a/public/app/plugins/panel/text/TextPanel.test.tsx b/public/app/plugins/panel/text/TextPanel.test.tsx index 08f034dc3df..04c86415e67 100644 --- a/public/app/plugins/panel/text/TextPanel.test.tsx +++ b/public/app/plugins/panel/text/TextPanel.test.tsx @@ -60,6 +60,15 @@ describe('TextPanel', () => { expect(() => setup()).not.toThrow(); }); + it('should not throw an error when interpolating variables results in empty content', () => { + const contentTest = '${__all_variables}'; + const props = Object.assign({}, defaultProps, { + options: { content: contentTest, mode: TextMode.HTML }, + }); + + expect(() => setup(props)).not.toThrow(); + }); + it('sanitizes content in html mode', () => { const contentTest = '
\n'; replaceVariablesMock.mockReturnValueOnce(contentTest); diff --git a/public/app/plugins/panel/text/TextPanel.tsx b/public/app/plugins/panel/text/TextPanel.tsx index 98762f4a106..4f0c15ffcec 100644 --- a/public/app/plugins/panel/text/TextPanel.tsx +++ b/public/app/plugins/panel/text/TextPanel.tsx @@ -64,14 +64,15 @@ export function TextPanel(props: Props) { function processContent(options: Options, interpolate: InterpolateFunction, disableSanitizeHtml: boolean): string { let { mode, content } = options; - if (!content) { - return ' '; - } // Variables must be interpolated before content is converted to markdown so using variables // in URLs work properly content = interpolate(content, {}, options.code?.language === 'json' ? 'json' : 'html'); + if (!content) { + return ' '; + } + switch (mode) { case TextMode.Code: break; // nothing