@capillarytech/cap-ui-utils 1.4.25-alpha.0 → 1.4.25-alpha.1
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/package.json
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import { JSDOM } from 'jsdom';
|
|
2
|
-
import createDOMPurify from 'dompurify';
|
|
3
|
-
import isEmpty from 'lodash/isEmpty';
|
|
4
|
-
|
|
5
|
-
export const sanitizeTemplateWithDomPurify = (content) => {
|
|
6
|
-
const window = new JSDOM('<textarea id="a1" />').window;
|
|
7
|
-
const textElement = window.document.getElementById("a1");
|
|
8
|
-
textElement.innerHTML = content;
|
|
9
|
-
const DOMPurify = createDOMPurify(window);
|
|
10
|
-
return DOMPurify.sanitize(content);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
1
|
export const sanitizeTemplateWithRegexp = (content) => {
|
|
15
2
|
const forbiddenTags = process.env.TMPL_SANITIZE_FORBIDDEN_TAGS ? JSON.parse(process.env.TMPL_SANITIZE_FORBIDDEN_TAGS) : ['script'];
|
|
16
3
|
const forbiddenAttrs = process.env.TMPL_SANITIZE_FORBIDDEN_ATTRS ? JSON.parse(process.env.TMPL_SANITIZE_FORBIDDEN_ATTRS) : ['onclick', 'onmouseover', 'onmouseout'];
|
|
@@ -33,39 +20,3 @@ export const sanitizeTemplateWithRegexp = (content) => {
|
|
|
33
20
|
.replaceAll(hrefJavaScriptRegex, 'href="#"')
|
|
34
21
|
.replaceAll(hrefRegexForJsonString, 'href=\\\"#\\\"'); // This will ensure to remain the content in json format for BEE editor
|
|
35
22
|
};
|
|
36
|
-
|
|
37
|
-
export const sanitizeEmailTemplateAndSaveInData = data => {
|
|
38
|
-
var content = data?.versions?.base?.[data?.versions?.base?.activeTab]['template-content'];
|
|
39
|
-
var sanitizedContent = sanitizeTemplateWithRegexp(content);
|
|
40
|
-
const newData = {
|
|
41
|
-
...data,
|
|
42
|
-
versions: {
|
|
43
|
-
...data.versions,
|
|
44
|
-
base: {
|
|
45
|
-
...data.versions.base,
|
|
46
|
-
[data.versions.base.activeTab]: {
|
|
47
|
-
...data.versions.base[data.versions.base.activeTab],
|
|
48
|
-
'template-content': sanitizedContent
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
history: [{
|
|
52
|
-
...data.versions.history[0],
|
|
53
|
-
[data.versions.history[0].activeTab]: {
|
|
54
|
-
...data.versions.history[0][data.versions.history[0].activeTab],
|
|
55
|
-
'template-content': sanitizedContent
|
|
56
|
-
}
|
|
57
|
-
}]
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// To handle in BEE editor. // is_drag_drop=true means BEE editor is enabled
|
|
62
|
-
if (data?.versions?.base?.[data?.versions?.base?.activeTab]?.is_drag_drop) {
|
|
63
|
-
const jsonContent = data?.versions?.base?.[data?.versions?.base?.activeTab]?.['json-content'];
|
|
64
|
-
if (!isEmpty(jsonContent)) {
|
|
65
|
-
const sanitizedJsonContent = sanitizeTemplateWithRegexp(jsonContent);
|
|
66
|
-
newData.versions.base[newData?.versions?.base?.activeTab]['json-content'] = sanitizedJsonContent;
|
|
67
|
-
newData.versions.history[0][newData?.versions?.history?.[0]?.activeTab]['json-content'] = sanitizedJsonContent;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return { sanitizedContent, newData };
|
|
71
|
-
};
|