@webex/helper-html 2.59.8-next.1 → 2.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/html.js +5 -9
- package/dist/html.js.map +1 -1
- package/dist/html.shim.js +17 -20
- package/dist/html.shim.js.map +1 -1
- package/package.json +11 -12
package/dist/html.js
CHANGED
|
@@ -19,12 +19,8 @@ _Object$defineProperty(exports, "escapeSync", {
|
|
|
19
19
|
});
|
|
20
20
|
exports.filterSync = exports.filterEscapeSync = exports.filterEscape = exports.filter = void 0;
|
|
21
21
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
22
|
-
var
|
|
22
|
+
var _curry2 = _interopRequireDefault(require("lodash/curry"));
|
|
23
23
|
var _htmlBase = require("./html-base");
|
|
24
|
-
/*!
|
|
25
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
24
|
/**
|
|
29
25
|
* @param {Object} allowedTags
|
|
30
26
|
* @param {Array<string>} allowedStyles
|
|
@@ -53,12 +49,12 @@ function noop() {
|
|
|
53
49
|
function noopSync(processCallback, allowedTags, allowedStyles, html) {
|
|
54
50
|
return html;
|
|
55
51
|
}
|
|
56
|
-
var filter = (0,
|
|
52
|
+
var filter = (0, _curry2.default)(noop, 4);
|
|
57
53
|
exports.filter = filter;
|
|
58
|
-
var filterSync = (0,
|
|
54
|
+
var filterSync = (0, _curry2.default)(noopSync, 4);
|
|
59
55
|
exports.filterSync = filterSync;
|
|
60
|
-
var filterEscape = (0,
|
|
56
|
+
var filterEscape = (0, _curry2.default)(noop, 4);
|
|
61
57
|
exports.filterEscape = filterEscape;
|
|
62
|
-
var filterEscapeSync = (0,
|
|
58
|
+
var filterEscapeSync = (0, _curry2.default)(noopSync, 4);
|
|
63
59
|
exports.filterEscapeSync = filterEscapeSync;
|
|
64
60
|
//# sourceMappingURL=html.js.map
|
package/dist/html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_htmlBase","require","noop","_len","arguments","length","args","Array","_key","_promise","default","resolve","noopSync","apply","processCallback","allowedTags","allowedStyles","html","filter","_curry2","exports","filterSync","filterEscape","filterEscapeSync"],"sources":["html.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {curry} from 'lodash';\n\nexport {escape, escapeSync} from './html-base';\n\n/**\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @private\n * @returns {string}\n */\nfunction noop(...args) {\n return new Promise((resolve) => {\n resolve(noopSync(...args));\n });\n}\n\n/**\n * @param {function} processCallback callback function to do additional\n * processing on node. of the form process(node)\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @private\n * @returns {string}\n */\nfunction noopSync(processCallback, allowedTags, allowedStyles, html) {\n return html;\n}\n\nexport const filter = curry(noop, 4);\nexport const filterSync = curry(noopSync, 4);\nexport const filterEscape = curry(noop, 4);\nexport const filterEscapeSync = curry(noopSync, 4);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAMA,IAAAA,SAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,IAAIA,CAAA,EAAU;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAANC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAJF,IAAI,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;EAAA;EACnB,OAAO,IAAAC,QAAA,CAAAC,OAAA,CAAY,UAACC,OAAO,EAAK;IAC9BA,OAAO,CAACC,QAAQ,CAAAC,KAAA,SAAIP,IAAI,CAAC,CAAC;EAC5B,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASM,QAAQA,CAACE,eAAe,EAAEC,WAAW,EAAEC,aAAa,EAAEC,IAAI,EAAE;EACnE,OAAOA,IAAI;AACb;AAEO,IAAMC,MAAM,GAAG,IAAAC,OAAA,CAAAT,OAAA,EAAMR,IAAI,EAAE,CAAC,CAAC;AAACkB,OAAA,CAAAF,MAAA,GAAAA,MAAA;AAC9B,IAAMG,UAAU,GAAG,IAAAF,OAAA,CAAAT,OAAA,EAAME,QAAQ,EAAE,CAAC,CAAC;AAACQ,OAAA,CAAAC,UAAA,GAAAA,UAAA;AACtC,IAAMC,YAAY,GAAG,IAAAH,OAAA,CAAAT,OAAA,EAAMR,IAAI,EAAE,CAAC,CAAC;AAACkB,OAAA,CAAAE,YAAA,GAAAA,YAAA;AACpC,IAAMC,gBAAgB,GAAG,IAAAJ,OAAA,CAAAT,OAAA,EAAME,QAAQ,EAAE,CAAC,CAAC;AAACQ,OAAA,CAAAG,gBAAA,GAAAA,gBAAA"}
|
package/dist/html.shim.js
CHANGED
|
@@ -20,14 +20,11 @@ _Object$defineProperty(exports, "escapeSync", {
|
|
|
20
20
|
exports.filterSync = exports.filterEscapeSync = exports.filterEscape = exports.filter = void 0;
|
|
21
21
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
22
22
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));
|
|
23
|
-
var
|
|
23
|
+
var _reduce2 = _interopRequireDefault(require("lodash/reduce"));
|
|
24
|
+
var _includes2 = _interopRequireDefault(require("lodash/includes"));
|
|
25
|
+
var _forEach2 = _interopRequireDefault(require("lodash/forEach"));
|
|
26
|
+
var _curry2 = _interopRequireDefault(require("lodash/curry"));
|
|
24
27
|
var _htmlBase = require("./html-base");
|
|
25
|
-
/*!
|
|
26
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/* eslint-env browser */
|
|
30
|
-
|
|
31
28
|
/**
|
|
32
29
|
* Some browsers don't implement {@link Element#remove()} or
|
|
33
30
|
* {@link NodeList#remove()} or {@link HTMLCollection#remove()}. This wrapper
|
|
@@ -77,7 +74,7 @@ function _filter() {
|
|
|
77
74
|
* @param {string} html html to filter
|
|
78
75
|
* @returns {string}
|
|
79
76
|
*/
|
|
80
|
-
var filter = (0,
|
|
77
|
+
var filter = (0, _curry2.default)(_filter, 4);
|
|
81
78
|
|
|
82
79
|
/**
|
|
83
80
|
* @param {function} processCallback callback function to do additional
|
|
@@ -116,10 +113,10 @@ function _filterSync(processCallback, allowedTags, allowedStyles, html) {
|
|
|
116
113
|
var nodeName = node.nodeName.toLowerCase();
|
|
117
114
|
var allowedTagNames = (0, _keys.default)(allowedTags);
|
|
118
115
|
depthFirstForEach(node.childNodes, filterNode);
|
|
119
|
-
if ((0,
|
|
116
|
+
if ((0, _includes2.default)(allowedTagNames, nodeName)) {
|
|
120
117
|
var allowedAttributes = allowedTags[nodeName];
|
|
121
|
-
(0,
|
|
122
|
-
if (!(0,
|
|
118
|
+
(0, _forEach2.default)(listAttributeNames(node.attributes), function (attrName) {
|
|
119
|
+
if (!(0, _includes2.default)(allowedAttributes, attrName)) {
|
|
123
120
|
node.removeAttribute(attrName);
|
|
124
121
|
} else if (attrName === 'href' || attrName === 'src') {
|
|
125
122
|
var attrValue = node.attributes.getNamedItem(attrName).value.trim().toLowerCase();
|
|
@@ -133,7 +130,7 @@ function _filterSync(processCallback, allowedTags, allowedStyles, html) {
|
|
|
133
130
|
} else if (attrName === 'style') {
|
|
134
131
|
var styles = node.attributes.getNamedItem('style').value.split(';').map(function (style) {
|
|
135
132
|
var styleName = trim(style.split(':')[0]);
|
|
136
|
-
if ((0,
|
|
133
|
+
if ((0, _includes2.default)(allowedStyles, styleName)) {
|
|
137
134
|
return style;
|
|
138
135
|
}
|
|
139
136
|
return null;
|
|
@@ -201,10 +198,10 @@ function _filterEscapeSync(processCallback, allowedTags, allowedStyles, html) {
|
|
|
201
198
|
depthFirstForEach(node.childNodes, filterNode);
|
|
202
199
|
var nodeName = node.nodeName.toLowerCase();
|
|
203
200
|
var allowedTagNames = (0, _keys.default)(allowedTags);
|
|
204
|
-
if ((0,
|
|
201
|
+
if ((0, _includes2.default)(allowedTagNames, nodeName)) {
|
|
205
202
|
var allowedAttributes = allowedTags[nodeName];
|
|
206
|
-
(0,
|
|
207
|
-
if (!(0,
|
|
203
|
+
(0, _forEach2.default)(listAttributeNames(node.attributes), function (attrName) {
|
|
204
|
+
if (!(0, _includes2.default)(allowedAttributes, attrName)) {
|
|
208
205
|
node.removeAttribute(attrName);
|
|
209
206
|
} else if (attrName === 'href' || attrName === 'src') {
|
|
210
207
|
var attrValue = node.attributes.getNamedItem(attrName).value.toLowerCase();
|
|
@@ -218,7 +215,7 @@ function _filterEscapeSync(processCallback, allowedTags, allowedStyles, html) {
|
|
|
218
215
|
} else if (attrName === 'style') {
|
|
219
216
|
var styles = node.attributes.getNamedItem('style').value.split(';').map(function (style) {
|
|
220
217
|
var styleName = trim(style.split(':')[0]);
|
|
221
|
-
if ((0,
|
|
218
|
+
if ((0, _includes2.default)(allowedStyles, styleName)) {
|
|
222
219
|
return style;
|
|
223
220
|
}
|
|
224
221
|
return null;
|
|
@@ -277,7 +274,7 @@ function reparent(node) {
|
|
|
277
274
|
* @returns {Array<string>}
|
|
278
275
|
*/
|
|
279
276
|
function listAttributeNames(attributes) {
|
|
280
|
-
return (0,
|
|
277
|
+
return (0, _reduce2.default)(attributes, function (attrNames, attr) {
|
|
281
278
|
attrNames.push(attr.name);
|
|
282
279
|
return attrNames;
|
|
283
280
|
}, []);
|
|
@@ -323,7 +320,7 @@ function isElement(o) {
|
|
|
323
320
|
* @param {string} html html to filter
|
|
324
321
|
* @returns {string}
|
|
325
322
|
*/
|
|
326
|
-
var filterSync = (0,
|
|
323
|
+
var filterSync = (0, _curry2.default)(_filterSync, 4);
|
|
327
324
|
|
|
328
325
|
/**
|
|
329
326
|
* Curried HTML filter that escapes rather than removes disallowed tags
|
|
@@ -333,7 +330,7 @@ var filterSync = (0, _lodash.curry)(_filterSync, 4);
|
|
|
333
330
|
* @returns {Promise<string>}
|
|
334
331
|
*/
|
|
335
332
|
exports.filterSync = filterSync;
|
|
336
|
-
var filterEscape = (0,
|
|
333
|
+
var filterEscape = (0, _curry2.default)(_filterEscape, 4);
|
|
337
334
|
|
|
338
335
|
/**
|
|
339
336
|
* Curried HTML filter that escapes rather than removes disallowed tags
|
|
@@ -343,6 +340,6 @@ var filterEscape = (0, _lodash.curry)(_filterEscape, 4);
|
|
|
343
340
|
* @returns {string}
|
|
344
341
|
*/
|
|
345
342
|
exports.filterEscape = filterEscape;
|
|
346
|
-
var filterEscapeSync = (0,
|
|
343
|
+
var filterEscapeSync = (0, _curry2.default)(_filterEscapeSync, 4);
|
|
347
344
|
exports.filterEscapeSync = filterEscapeSync;
|
|
348
345
|
//# sourceMappingURL=html.shim.js.map
|
package/dist/html.shim.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_lodash","require","_htmlBase","removeNode","node","remove","parentElement","removeChild","i","length","Error","_filter","_len","arguments","args","Array","_key","_promise","default","resolve","_filterSync","apply","filter","curry","exports","processCallback","allowedTags","allowedStyles","html","doc","DOMParser","parseFromString","depthFirstForEach","body","childNodes","filterNode","indexOf","concat","innerHTML","isElement","nodeName","toLowerCase","allowedTagNames","_keys","includes","allowedAttributes","forEach","listAttributeNames","attributes","attrName","removeAttribute","attrValue","getNamedItem","value","trim","reparent","styles","split","map","style","styleName","Boolean","join","setAttribute","_filterEscape","_len2","_key2","_filterEscapeSync","escapeNode","before","document","createTextNode","after","parentNode","insertBefore","trimPattern","str","replace","reduce","attrNames","attr","push","name","list","fn","o","ownerDocument","undefined","nodeType","filterSync","filterEscape","filterEscapeSync"],"sources":["html.shim.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env browser */\n\nimport {curry, forEach, includes, reduce} from 'lodash';\n\nexport {escape, escapeSync} from './html-base';\n\n/**\n * Some browsers don't implement {@link Element#remove()} or\n * {@link NodeList#remove()} or {@link HTMLCollection#remove()}. This wrapper\n * calls the appropriate `#remove()` method if available, or falls back to a\n * non-global-polluting polyfill.\n * @param {Element|NodeList|HTMLCollection} node\n * @returns {undefined}\n */\nfunction removeNode(node) {\n if (node.remove) {\n node.remove();\n\n return;\n }\n\n if (node.parentElement) {\n node.parentElement.removeChild(node);\n\n return;\n }\n\n if ('length' in node) {\n for (let i = node.length - 1; i >= 0; i -= 1) {\n removeNode(node[i]);\n }\n\n return;\n }\n\n throw new Error('Could not find a way to remove node');\n}\n\n/**\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @private\n * @returns {string}\n */\nfunction _filter(...args) {\n return new Promise((resolve) => {\n resolve(_filterSync(...args));\n });\n}\n\n/**\n * Curried async HTML filter.\n * @param {Object} allowedTags Map of tagName -> array of allowed attributes\n * @param {Array<string>} allowedStyles Array of allowed styles\n * @param {string} html html to filter\n * @returns {string}\n */\nexport const filter = curry(_filter, 4);\n\n/**\n * @param {function} processCallback callback function to do additional\n * processing on node. of the form process(node)\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @private\n * @returns {string}\n */\nfunction _filterSync(processCallback, allowedTags, allowedStyles, html) {\n if (!html || !allowedStyles || !allowedTags) {\n if (html.length === 0) {\n return html;\n }\n\n throw new Error('`allowedTags`, `allowedStyles`, and `html` must be provided');\n }\n\n const doc = new DOMParser().parseFromString(html, 'text/html');\n\n depthFirstForEach(doc.body.childNodes, filterNode);\n processCallback(doc.body);\n\n if (html.indexOf('body') === 1) {\n return `<body>${doc.body.innerHTML}</body>`;\n }\n\n return doc.body.innerHTML;\n\n /**\n * @param {Node} node\n * @private\n * @returns {undefined}\n */\n function filterNode(node) {\n if (!isElement(node)) {\n return;\n }\n\n const nodeName = node.nodeName.toLowerCase();\n const allowedTagNames = Object.keys(allowedTags);\n\n depthFirstForEach(node.childNodes, filterNode);\n\n if (includes(allowedTagNames, nodeName)) {\n const allowedAttributes = allowedTags[nodeName];\n\n forEach(listAttributeNames(node.attributes), (attrName) => {\n if (!includes(allowedAttributes, attrName)) {\n node.removeAttribute(attrName);\n } else if (attrName === 'href' || attrName === 'src') {\n const attrValue = node.attributes.getNamedItem(attrName).value.trim().toLowerCase();\n\n // We're doing at runtime what the no-script-url rule does at compile\n // time\n // eslint-disable-next-line no-script-url\n if (attrValue.indexOf('javascript:') === 0 || attrValue.indexOf('vbscript:') === 0) {\n reparent(node);\n }\n } else if (attrName === 'style') {\n const styles = node.attributes\n .getNamedItem('style')\n .value.split(';')\n .map((style) => {\n const styleName = trim(style.split(':')[0]);\n\n if (includes(allowedStyles, styleName)) {\n return style;\n }\n\n return null;\n })\n .filter((style) => Boolean(style))\n .join(';');\n\n node.setAttribute('style', styles);\n }\n });\n } else {\n reparent(node);\n }\n }\n}\n\n/**\n * Same as _filter, but escapes rather than removes disallowed values\n * @param {Function} processCallback\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @returns {Promise<string>}\n */\nfunction _filterEscape(...args) {\n return new Promise((resolve) => {\n resolve(_filterEscapeSync(...args));\n });\n}\n\n/**\n * Same as _filterSync, but escapes rather than removes disallowed values\n * @param {Function} processCallback\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @returns {string}\n */\nfunction _filterEscapeSync(processCallback, allowedTags, allowedStyles, html) {\n if (!html || !allowedStyles || !allowedTags) {\n if (html.length === 0) {\n return html;\n }\n\n throw new Error('`allowedTags`, `allowedStyles`, and `html` must be provided');\n }\n\n const doc = new DOMParser().parseFromString(html, 'text/html');\n\n depthFirstForEach(doc.body.childNodes, filterNode);\n processCallback(doc.body);\n\n if (html.indexOf('body') === 1) {\n return `<body>${doc.body.innerHTML}</body>`;\n }\n\n return doc.body.innerHTML;\n\n /**\n * @param {Node} node\n * @private\n * @returns {undefined}\n */\n function filterNode(node) {\n if (!isElement(node)) {\n return;\n }\n\n depthFirstForEach(node.childNodes, filterNode);\n\n const nodeName = node.nodeName.toLowerCase();\n const allowedTagNames = Object.keys(allowedTags);\n\n if (includes(allowedTagNames, nodeName)) {\n const allowedAttributes = allowedTags[nodeName];\n\n forEach(listAttributeNames(node.attributes), (attrName) => {\n if (!includes(allowedAttributes, attrName)) {\n node.removeAttribute(attrName);\n } else if (attrName === 'href' || attrName === 'src') {\n const attrValue = node.attributes.getNamedItem(attrName).value.toLowerCase();\n\n // We're doing at runtime what the no-script-url rule does at compile\n // time\n // eslint-disable-next-line no-script-url\n if (attrValue.indexOf('javascript:') === 0 || attrValue.indexOf('vbscript:') === 0) {\n reparent(node);\n }\n } else if (attrName === 'style') {\n const styles = node.attributes\n .getNamedItem('style')\n .value.split(';')\n .map((style) => {\n const styleName = trim(style.split(':')[0]);\n\n if (includes(allowedStyles, styleName)) {\n return style;\n }\n\n return null;\n })\n .filter((style) => Boolean(style))\n .join(';');\n\n node.setAttribute('style', styles);\n }\n });\n } else {\n escapeNode(node);\n }\n }\n}\n\n/**\n * Escapes a given html node\n * @param {Node} node\n * @returns {undefined}\n */\nfunction escapeNode(node) {\n const before = document.createTextNode(`<${node.nodeName.toLowerCase()}>`);\n const after = document.createTextNode(`</${node.nodeName.toLowerCase()}>`);\n\n node.parentNode.insertBefore(before, node);\n while (node.childNodes.length > 0) {\n node.parentNode.insertBefore(node.childNodes[0], node);\n }\n node.parentNode.insertBefore(after, node);\n\n removeNode(node);\n}\n\nconst trimPattern = /^\\s|\\s$/g;\n\n/**\n * @param {string} str\n * @returns {string}\n */\nfunction trim(str) {\n return str.replace(trimPattern, '');\n}\n\n/**\n * @param {Node} node\n * @private\n * @returns {undefined}\n */\nfunction reparent(node) {\n while (node.childNodes.length > 0) {\n node.parentNode.insertBefore(node.childNodes[0], node);\n }\n removeNode(node);\n}\n\n/**\n * @param {NamedNodeMap} attributes\n * @private\n * @returns {Array<string>}\n */\nfunction listAttributeNames(attributes) {\n return reduce(\n attributes,\n (attrNames, attr) => {\n attrNames.push(attr.name);\n\n return attrNames;\n },\n []\n );\n}\n\n/**\n * @param {Array} list\n * @param {Function} fn\n * @private\n * @returns {undefined}\n */\nfunction depthFirstForEach(list, fn) {\n for (let i = list.length; i >= 0; i -= 1) {\n fn(list[i]);\n }\n}\n\n/**\n * @param {Node} o\n * @private\n * @returns {Boolean}\n */\nfunction isElement(o) {\n if (!o) {\n return false;\n }\n\n if (o.ownerDocument === undefined) {\n return false;\n }\n\n if (o.nodeType !== 1) {\n return false;\n }\n\n if (typeof o.nodeName !== 'string') {\n return false;\n }\n\n return true;\n}\n\n/**\n * Curried HTML filter.\n * @param {Object} allowedTags Map of tagName -> array of allowed attributes\n * @param {Array<string>} allowedStyles Array of allowed styles\n * @param {string} html html to filter\n * @returns {string}\n */\nexport const filterSync = curry(_filterSync, 4);\n\n/**\n * Curried HTML filter that escapes rather than removes disallowed tags\n * @param {Object} allowedTags Map of tagName -> array of allowed attributes\n * @param {Array<string>} allowedStyles Array of allowed styles\n * @param {string} html html to filter\n * @returns {Promise<string>}\n */\nexport const filterEscape = curry(_filterEscape, 4);\n\n/**\n * Curried HTML filter that escapes rather than removes disallowed tags\n * @param {Object} allowedTags Map of tagName -> array of allowed attributes\n * @param {Array<string>} allowedStyles Array of allowed styles\n * @param {string} html html to filter\n * @returns {string}\n */\nexport const filterEscapeSync = curry(_filterEscapeSync, 4);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAEA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,UAAUA,CAACC,IAAI,EAAE;EACxB,IAAIA,IAAI,CAACC,MAAM,EAAE;IACfD,IAAI,CAACC,MAAM,EAAE;IAEb;EACF;EAEA,IAAID,IAAI,CA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iBAAiB,EAAE,CAAC,CAAC;AAAC3C,OAAA,CAAAmE,gBAAA,GAAAA,gBAAA"}
|
|
1
|
+
{"version":3,"names":["_htmlBase","require","removeNode","node","remove","parentElement","removeChild","i","length","Error","_filter","_len","arguments","args","Array","_key","_promise","default","resolve","_filterSync","apply","filter","_curry2","exports","processCallback","allowedTags","allowedStyles","html","doc","DOMParser","parseFromString","depthFirstForEach","body","childNodes","filterNode","indexOf","concat","innerHTML","isElement","nodeName","toLowerCase","allowedTagNames","_keys","_includes2","allowedAttributes","_forEach2","listAttributeNames","attributes","attrName","removeAttribute","attrValue","getNamedItem","value","trim","reparent","styles","split","map","style","styleName","Boolean","join","setAttribute","_filterEscape","_len2","_key2","_filterEscapeSync","escapeNode","before","document","createTextNode","after","parentNode","insertBefore","trimPattern","str","replace","_reduce2","attrNames","attr","push","name","list","fn","o","ownerDocument","undefined","nodeType","filterSync","filterEscape","filterEscapeSync"],"sources":["html.shim.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\n/* eslint-env browser */\n\nimport {curry, forEach, includes, reduce} from 'lodash';\n\nexport {escape, escapeSync} from './html-base';\n\n/**\n * Some browsers don't implement {@link Element#remove()} or\n * {@link NodeList#remove()} or {@link HTMLCollection#remove()}. This wrapper\n * calls the appropriate `#remove()` method if available, or falls back to a\n * non-global-polluting polyfill.\n * @param {Element|NodeList|HTMLCollection} node\n * @returns {undefined}\n */\nfunction removeNode(node) {\n if (node.remove) {\n node.remove();\n\n return;\n }\n\n if (node.parentElement) {\n node.parentElement.removeChild(node);\n\n return;\n }\n\n if ('length' in node) {\n for (let i = node.length - 1; i >= 0; i -= 1) {\n removeNode(node[i]);\n }\n\n return;\n }\n\n throw new Error('Could not find a way to remove node');\n}\n\n/**\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @private\n * @returns {string}\n */\nfunction _filter(...args) {\n return new Promise((resolve) => {\n resolve(_filterSync(...args));\n });\n}\n\n/**\n * Curried async HTML filter.\n * @param {Object} allowedTags Map of tagName -> array of allowed attributes\n * @param {Array<string>} allowedStyles Array of allowed styles\n * @param {string} html html to filter\n * @returns {string}\n */\nexport const filter = curry(_filter, 4);\n\n/**\n * @param {function} processCallback callback function to do additional\n * processing on node. of the form process(node)\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @private\n * @returns {string}\n */\nfunction _filterSync(processCallback, allowedTags, allowedStyles, html) {\n if (!html || !allowedStyles || !allowedTags) {\n if (html.length === 0) {\n return html;\n }\n\n throw new Error('`allowedTags`, `allowedStyles`, and `html` must be provided');\n }\n\n const doc = new DOMParser().parseFromString(html, 'text/html');\n\n depthFirstForEach(doc.body.childNodes, filterNode);\n processCallback(doc.body);\n\n if (html.indexOf('body') === 1) {\n return `<body>${doc.body.innerHTML}</body>`;\n }\n\n return doc.body.innerHTML;\n\n /**\n * @param {Node} node\n * @private\n * @returns {undefined}\n */\n function filterNode(node) {\n if (!isElement(node)) {\n return;\n }\n\n const nodeName = node.nodeName.toLowerCase();\n const allowedTagNames = Object.keys(allowedTags);\n\n depthFirstForEach(node.childNodes, filterNode);\n\n if (includes(allowedTagNames, nodeName)) {\n const allowedAttributes = allowedTags[nodeName];\n\n forEach(listAttributeNames(node.attributes), (attrName) => {\n if (!includes(allowedAttributes, attrName)) {\n node.removeAttribute(attrName);\n } else if (attrName === 'href' || attrName === 'src') {\n const attrValue = node.attributes.getNamedItem(attrName).value.trim().toLowerCase();\n\n // We're doing at runtime what the no-script-url rule does at compile\n // time\n // eslint-disable-next-line no-script-url\n if (attrValue.indexOf('javascript:') === 0 || attrValue.indexOf('vbscript:') === 0) {\n reparent(node);\n }\n } else if (attrName === 'style') {\n const styles = node.attributes\n .getNamedItem('style')\n .value.split(';')\n .map((style) => {\n const styleName = trim(style.split(':')[0]);\n\n if (includes(allowedStyles, styleName)) {\n return style;\n }\n\n return null;\n })\n .filter((style) => Boolean(style))\n .join(';');\n\n node.setAttribute('style', styles);\n }\n });\n } else {\n reparent(node);\n }\n }\n}\n\n/**\n * Same as _filter, but escapes rather than removes disallowed values\n * @param {Function} processCallback\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @returns {Promise<string>}\n */\nfunction _filterEscape(...args) {\n return new Promise((resolve) => {\n resolve(_filterEscapeSync(...args));\n });\n}\n\n/**\n * Same as _filterSync, but escapes rather than removes disallowed values\n * @param {Function} processCallback\n * @param {Object} allowedTags\n * @param {Array<string>} allowedStyles\n * @param {string} html\n * @returns {string}\n */\nfunction _filterEscapeSync(processCallback, allowedTags, allowedStyles, html) {\n if (!html || !allowedStyles || !allowedTags) {\n if (html.length === 0) {\n return html;\n }\n\n throw new Error('`allowedTags`, `allowedStyles`, and `html` must be provided');\n }\n\n const doc = new DOMParser().parseFromString(html, 'text/html');\n\n depthFirstForEach(doc.body.childNodes, filterNode);\n processCallback(doc.body);\n\n if (html.indexOf('body') === 1) {\n return `<body>${doc.body.innerHTML}</body>`;\n }\n\n return doc.body.innerHTML;\n\n /**\n * @param {Node} node\n * @private\n * @returns {undefined}\n */\n function filterNode(node) {\n if (!isElement(node)) {\n return;\n }\n\n depthFirstForEach(node.childNodes, filterNode);\n\n const nodeName = node.nodeName.toLowerCase();\n const allowedTagNames = Object.keys(allowedTags);\n\n if (includes(allowedTagNames, nodeName)) {\n const allowedAttributes = allowedTags[nodeName];\n\n forEach(listAttributeNames(node.attributes), (attrName) => {\n if (!includes(allowedAttributes, attrName)) {\n node.removeAttribute(attrName);\n } else if (attrName === 'href' || attrName === 'src') {\n const attrValue = node.attributes.getNamedItem(attrName).value.toLowerCase();\n\n // We're doing at runtime what the no-script-url rule does at compile\n // time\n // eslint-disable-next-line no-script-url\n if (attrValue.indexOf('javascript:') === 0 || attrValue.indexOf('vbscript:') === 0) {\n reparent(node);\n }\n } else if (attrName === 'style') {\n const styles = node.attributes\n .getNamedItem('style')\n .value.split(';')\n .map((style) => {\n const styleName = trim(style.split(':')[0]);\n\n if (includes(allowedStyles, styleName)) {\n return style;\n }\n\n return null;\n })\n .filter((style) => Boolean(style))\n .join(';');\n\n node.setAttribute('style', styles);\n }\n });\n } else {\n escapeNode(node);\n }\n }\n}\n\n/**\n * Escapes a given html node\n * @param {Node} node\n * @returns {undefined}\n */\nfunction escapeNode(node) {\n const before = document.createTextNode(`<${node.nodeName.toLowerCase()}>`);\n const after = document.createTextNode(`</${node.nodeName.toLowerCase()}>`);\n\n node.parentNode.insertBefore(before, node);\n while (node.childNodes.length > 0) {\n node.parentNode.insertBefore(node.childNodes[0], node);\n }\n node.parentNode.insertBefore(after, node);\n\n removeNode(node);\n}\n\nconst trimPattern = /^\\s|\\s$/g;\n\n/**\n * @param {string} str\n * @returns {string}\n */\nfunction trim(str) {\n return str.replace(trimPattern, '');\n}\n\n/**\n * @param {Node} node\n * @private\n * @returns {undefined}\n */\nfunction reparent(node) {\n while (node.childNodes.length > 0) {\n node.parentNode.insertBefore(node.childNodes[0], node);\n }\n removeNode(node);\n}\n\n/**\n * @param {NamedNodeMap} attributes\n * @private\n * @returns {Array<string>}\n */\nfunction listAttributeNames(attributes) {\n return reduce(\n attributes,\n (attrNames, attr) => {\n attrNames.push(attr.name);\n\n return attrNames;\n },\n []\n );\n}\n\n/**\n * @param {Array} list\n * @param {Function} fn\n * @private\n * @returns {undefined}\n */\nfunction depthFirstForEach(list, fn) {\n for (let i = list.length; i >= 0; i -= 1) {\n fn(list[i]);\n }\n}\n\n/**\n * @param {Node} o\n * @private\n * @returns {Boolean}\n */\nfunction isElement(o) {\n if (!o) {\n return false;\n }\n\n if (o.ownerDocument === undefined) {\n return false;\n }\n\n if (o.nodeType !== 1) {\n return false;\n }\n\n if (typeof o.nodeName !== 'string') {\n return false;\n }\n\n return true;\n}\n\n/**\n * Curried HTML filter.\n * @param {Object} allowedTags Map of tagName -> array of allowed attributes\n * @param {Array<string>} allowedStyles Array of allowed styles\n * @param {string} html html to filter\n * @returns {string}\n */\nexport const filterSync = curry(_filterSync, 4);\n\n/**\n * Curried HTML filter that escapes rather than removes disallowed tags\n * @param {Object} allowedTags Map of tagName -> array of allowed attributes\n * @param {Array<string>} allowedStyles Array of allowed styles\n * @param {string} html html to filter\n * @returns {Promise<string>}\n */\nexport const filterEscape = curry(_filterEscape, 4);\n\n/**\n * Curried HTML filter that escapes rather than removes disallowed tags\n * @param {Object} allowedTags Map of tagName -> array of allowed attributes\n * @param {Array<string>} allowedStyles Array of allowed styles\n * @param {string} html html to filter\n * @returns {string}\n */\nexport const filterEscapeSync = curry(_filterEscapeSync, 4);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAAA,SAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,UAAUA,CAACC,IAAI,EAAE;EACxB,IAAIA,IAAI,CAACC,MAAM,EAAE;IACfD,IAAI,CAACC,MAAM,EAAE;IAEb;EACF;EAEA,IAAID,IAAI,CAACE,aAAa,EAAE;IACtBF,IAAI,CAACE,aAAa,CAACC,WAAW,CAACH,IAAI,CAAC;IAEpC;EACF;EAEA,IAAI,QAAQ,IAAIA,IAAI,EAAE;IACpB,KAAK,IAAII,CAAC,GAAGJ,IAAI,CAACK,MAAM,GAAG,CAAC,EAAED,CAAC,IAAI,CAAC,EAAEA,CAAC,IAAI,CAAC,EAAE;MAC5CL,UAAU,CAACC,IAAI,CAACI,CAAC,CAAC,CAAC;IACrB;IAEA;EACF;EAEA,MAAM,IAAIE,KAAK,CAAC,qCAAqC,CAAC;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,OAAOA,CAAA,EAAU;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAJ,MAAA,EAANK,IAAI,OAAAC,KAAA,CAAAH,IAAA,GAAAI,IAAA,MAAAA,IAAA,GAAAJ,IAAA,EAAAI,IAAA;IAAJF,IAAI,CAAAE,IAAA,IAAAH,SAAA,CAAAG,IAAA;E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F;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAS+B,SAASA,CAAC8C,CAAC,EAAE;EACpB,IAAI,CAACA,CAAC,EAAE;IACN,OAAO,KAAK;EACd;EAEA,IAAIA,CAAC,CAACC,aAAa,KAAKC,SAAS,EAAE;IACjC,OAAO,KAAK;EACd;EAEA,IAAIF,CAAC,CAACG,QAAQ,KAAK,CAAC,EAAE;IACpB,OAAO,KAAK;EACd;EAEA,IAAI,OAAOH,CAAC,CAAC7C,QAAQ,KAAK,QAAQ,EAAE;IAClC,OAAO,KAAK;EACd;EAEA,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMiD,UAAU,GAAG,IAAAlE,OAAA,CAAAL,OAAA,EAAME,WAAW,EAAE,CAAC,CAAC;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AANAI,OAAA,CAAAiE,UAAA,GAAAA,UAAA;AAOO,IAAMC,YAAY,GAAG,IAAAnE,OAAA,CAAAL,OAAA,EAAM8C,aAAa,EAAE,CAAC,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AANAxC,OAAA,CAAAkE,YAAA,GAAAA,YAAA;AAOO,IAAMC,gBAAgB,GAAG,IAAApE,OAAA,CAAAL,OAAA,EAAMiD,iBAAiB,EAAE,CAAC,CAAC;AAAC3C,OAAA,CAAAmE,gBAAA,GAAAA,gBAAA"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/helper-html",
|
|
3
|
+
"version": "2.60.0",
|
|
3
4
|
"description": "HTML Utiltities",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"main": "dist/index.js",
|
|
@@ -24,14 +25,14 @@
|
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@babel/core": "^7.17.10",
|
|
27
|
-
"@webex/babel-config-legacy": "
|
|
28
|
-
"@webex/eslint-config-legacy": "
|
|
29
|
-
"@webex/jest-config-legacy": "
|
|
30
|
-
"@webex/legacy-tools": "
|
|
31
|
-
"@webex/test-helper-chai": "
|
|
32
|
-
"@webex/test-helper-mocha": "
|
|
33
|
-
"@webex/test-helper-mock-webex": "
|
|
34
|
-
"@webex/test-helper-test-users": "
|
|
28
|
+
"@webex/babel-config-legacy": "2.60.0",
|
|
29
|
+
"@webex/eslint-config-legacy": "2.60.0",
|
|
30
|
+
"@webex/jest-config-legacy": "2.60.0",
|
|
31
|
+
"@webex/legacy-tools": "2.60.0",
|
|
32
|
+
"@webex/test-helper-chai": "2.60.0",
|
|
33
|
+
"@webex/test-helper-mocha": "2.60.0",
|
|
34
|
+
"@webex/test-helper-mock-webex": "2.60.0",
|
|
35
|
+
"@webex/test-helper-test-users": "2.60.0",
|
|
35
36
|
"eslint": "^8.24.0",
|
|
36
37
|
"prettier": "^2.7.1"
|
|
37
38
|
},
|
|
@@ -41,12 +42,10 @@
|
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "yarn build:src",
|
|
43
44
|
"build:src": "webex-legacy-tools build -dest \"./dist\" -src \"./src\" -js -ts -maps",
|
|
44
|
-
"deploy:npm": "yarn npm publish",
|
|
45
45
|
"test": "yarn test:style && yarn test:unit && yarn test:integration && yarn test:browser",
|
|
46
46
|
"test:browser": "webex-legacy-tools test --integration --unit --runner karma",
|
|
47
47
|
"test:integration": "webex-legacy-tools test --integration --runner mocha",
|
|
48
48
|
"test:style": "eslint ./src/**/*.*",
|
|
49
49
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
50
|
+
}
|
|
51
|
+
}
|