mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user