streamline kbn.addSlashes and add a test, streamline escaping in angular tip() function (#41066)

* streamline kbn.addSlashes and add a test, streamline escaping in angular tip() function
* switch to double-html-encoding when building intermediate string
This commit is contained in:
Dan Cech
2021-11-05 09:18:42 -04:00
committed by GitHub
parent d524dc6108
commit 993cb80fea
3 changed files with 13 additions and 10 deletions

View File

@@ -1,7 +1,6 @@
import angular from 'angular';
import Clipboard from 'clipboard';
import coreModule from '../core/core_module';
import kbn from 'app/core/utils/kbn';
import { appEvents } from 'app/core/core';
import { AppEvents } from '@grafana/data';
@@ -14,9 +13,11 @@ function tip($compile: any) {
'<i class="grafana-tip fa fa-' +
(attrs.icon || 'question-circle') +
'" bs-tooltip="\'' +
kbn.addSlashes(elem.text()) +
// here we double-html-encode any special characters in the source string
// this is needed so that the final html contains the encoded entities as they
// will be decoded when _t is parsed by angular
elem.text().replace(/[\'\"\\{}<>&]/g, (m: string) => '&amp;#' + m.charCodeAt(0) + ';') +
'\'"></i>';
_t = _t.replace(/{/g, '\\{').replace(/}/g, '\\}');
elem.replaceWith($compile(angular.element(_t))(scope));
},
};