@abtnode/util 1.16.44-beta-20250529-223630-10e16ac8 → 1.16.44-beta-20250601-083116-288e5ea5
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/lib/sanitize.js +50 -0
- package/package.json +7 -6
package/lib/sanitize.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const { initSanitize } = require('@blocklet/xss');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 对用户的输入进行清洗,移除掉内容中包含的标签
|
|
5
|
+
* @param {*} content
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
const sanitizeTag = (content) => {
|
|
9
|
+
if (!content || typeof content !== 'string') {
|
|
10
|
+
return content;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const sanitize = initSanitize({
|
|
14
|
+
whiteList: {},
|
|
15
|
+
stripIgnoreTag: true,
|
|
16
|
+
onIgnoreTag: false,
|
|
17
|
+
stripIgnoreTagBody: [],
|
|
18
|
+
});
|
|
19
|
+
return sanitize(content);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 对包含标签的内容进行转义
|
|
24
|
+
* @param {*} content
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
const escapeTag = (content) => {
|
|
28
|
+
if (!content || typeof content !== 'string') {
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const sanitize = initSanitize({
|
|
33
|
+
whiteList: {},
|
|
34
|
+
stripIgnoreTag: false,
|
|
35
|
+
onIgnoreTag: (tag, html) => html.replace(/</g, '<').replace(/>/g, '>'),
|
|
36
|
+
onIgnoreTagAttr: (tag, name, value) => {
|
|
37
|
+
return `${name}="${value}"`;
|
|
38
|
+
},
|
|
39
|
+
stripIgnoreTagBody: [],
|
|
40
|
+
escapeHtml: (html) => {
|
|
41
|
+
return html.replace(/</g, '<').replace(/>/g, '>');
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return sanitize(content);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
sanitizeTag,
|
|
49
|
+
escapeTag,
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.44-beta-
|
|
6
|
+
"version": "1.16.44-beta-20250601-083116-288e5ea5",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,12 +18,13 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.16.44-beta-
|
|
21
|
+
"@abtnode/constant": "1.16.44-beta-20250601-083116-288e5ea5",
|
|
22
22
|
"@arcblock/did": "1.20.11",
|
|
23
23
|
"@arcblock/pm2": "^5.4.0",
|
|
24
|
-
"@blocklet/constant": "1.16.44-beta-
|
|
25
|
-
"@blocklet/error": "^0.2.
|
|
26
|
-
"@blocklet/meta": "1.16.44-beta-
|
|
24
|
+
"@blocklet/constant": "1.16.44-beta-20250601-083116-288e5ea5",
|
|
25
|
+
"@blocklet/error": "^0.2.5",
|
|
26
|
+
"@blocklet/meta": "1.16.44-beta-20250601-083116-288e5ea5",
|
|
27
|
+
"@blocklet/xss": "^0.1.36",
|
|
27
28
|
"@ocap/client": "1.20.11",
|
|
28
29
|
"@ocap/mcrypto": "1.20.11",
|
|
29
30
|
"@ocap/util": "1.20.11",
|
|
@@ -87,5 +88,5 @@
|
|
|
87
88
|
"fs-extra": "^11.2.0",
|
|
88
89
|
"jest": "^29.7.0"
|
|
89
90
|
},
|
|
90
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "5d978739f099374dcc9d4ce9572eb343fd0c39b4"
|
|
91
92
|
}
|