mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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) => '&#' + m.charCodeAt(0) + ';') +
|
||||
'\'"></i>';
|
||||
_t = _t.replace(/{/g, '\\{').replace(/}/g, '\\}');
|
||||
elem.replaceWith($compile(angular.element(_t))(scope));
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user