Variables: variables in Markdown links are not interpolated (#51392)

* on a text panel first interpolate, then markdown, then sanitize;

* update devenv dashboard + e2e tests

* fix typo and undo changes in grafana/data

* handling of config option disableSanitizeHtml more readable when preparing markdown in text panel

* betterer

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
This commit is contained in:
Polina Boneva
2022-06-29 15:26:31 +03:00
committed by GitHub
parent 688164bbd6
commit f83f05d6b3
4 changed files with 32 additions and 15 deletions

View File

@@ -41,24 +41,34 @@ export class TextPanel extends PureComponent<Props, State> {
}
prepareHTML(html: string): string {
return this.interpolateAndSanitizeString(html);
const result = this.interpolateString(html);
return config.disableSanitizeHtml ? result : this.sanitizeString(result);
}
prepareMarkdown(content: string): string {
// Sanitize is disabled here as we handle that after variable interpolation
return this.interpolateAndSanitizeString(
renderTextPanelMarkdown(content, {
noSanitize: config.disableSanitizeHtml,
})
);
// Always interpolate variables before converting to markdown
// because `marked` replaces '{' and '}' in URLs with '%7B' and '%7D'
// See https://marked.js.org/demo
let result = this.interpolateString(content);
if (config.disableSanitizeHtml) {
result = renderTextPanelMarkdown(result, {
noSanitize: true,
});
return result;
}
result = renderTextPanelMarkdown(result);
return this.sanitizeString(result);
}
interpolateAndSanitizeString(content: string): string {
interpolateString(content: string): string {
const { replaceVariables } = this.props;
return replaceVariables(content, {}, 'html');
}
content = replaceVariables(content, {}, 'html');
return config.disableSanitizeHtml ? content : textUtil.sanitizeTextPanelContent(content);
sanitizeString(content: string): string {
return textUtil.sanitizeTextPanelContent(content);
}
processContent(options: PanelOptions): string {