MCPcopy Create free account
hub / github.com/apache/impala / sanitizeHtml

Function sanitizeHtml

www/bootstrap/js/bootstrap.js:2693–2732  ·  view source on GitHub ↗
(unsafeHtml, whiteList, sanitizeFn)

Source from the content-addressed store, hash-verified

2691 }
2692
2693 function sanitizeHtml(unsafeHtml, whiteList, sanitizeFn) {
2694 if (unsafeHtml.length === 0) {
2695 return unsafeHtml;
2696 }
2697
2698 if (sanitizeFn && typeof sanitizeFn === 'function') {
2699 return sanitizeFn(unsafeHtml);
2700 }
2701
2702 var domParser = new window.DOMParser();
2703 var createdDocument = domParser.parseFromString(unsafeHtml, 'text/html');
2704 var whitelistKeys = Object.keys(whiteList);
2705 var elements = [].slice.call(createdDocument.body.querySelectorAll('*'));
2706
2707 var _loop = function _loop(i, len) {
2708 var el = elements[i];
2709 var elName = el.nodeName.toLowerCase();
2710
2711 if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) {
2712 el.parentNode.removeChild(el);
2713 return "continue";
2714 }
2715
2716 var attributeList = [].slice.call(el.attributes);
2717 var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []);
2718 attributeList.forEach(function (attr) {
2719 if (!allowedAttribute(attr, whitelistedAttributes)) {
2720 el.removeAttribute(attr.nodeName);
2721 }
2722 });
2723 };
2724
2725 for (var i = 0, len = elements.length; i < len; i++) {
2726 var _ret = _loop(i, len);
2727
2728 if (_ret === "continue") continue;
2729 }
2730
2731 return createdDocument.body.innerHTML;
2732 }
2733
2734 /**
2735 * ------------------------------------------------------------------------

Callers 1

bootstrap.jsFile · 0.85

Calls 2

_loopFunction · 0.85
callMethod · 0.65

Tested by

no test coverage detected