@nocobase/utils 2.3.0-beta.5 → 2.4.0-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/lib/client.d.ts +1 -0
- package/lib/client.js +2 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/sanitize-rich-text-html.d.ts +9 -0
- package/lib/sanitize-rich-text-html.js +145 -0
- package/lib/storage-path.js +8 -1
- package/package.json +3 -2
package/lib/client.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from './ses';
|
|
|
29
29
|
export * from './i18n';
|
|
30
30
|
export * from './isPortalInBody';
|
|
31
31
|
export * from './parseHTML';
|
|
32
|
+
export * from './sanitize-rich-text-html';
|
|
32
33
|
export * from './uid';
|
|
33
34
|
export * from './url';
|
|
34
35
|
export * from './transformMultiColumnToSingleColumn';
|
package/lib/client.js
CHANGED
|
@@ -67,6 +67,7 @@ __reExport(client_exports, require("./ses"), module.exports);
|
|
|
67
67
|
__reExport(client_exports, require("./i18n"), module.exports);
|
|
68
68
|
__reExport(client_exports, require("./isPortalInBody"), module.exports);
|
|
69
69
|
__reExport(client_exports, require("./parseHTML"), module.exports);
|
|
70
|
+
__reExport(client_exports, require("./sanitize-rich-text-html"), module.exports);
|
|
70
71
|
__reExport(client_exports, require("./uid"), module.exports);
|
|
71
72
|
__reExport(client_exports, require("./url"), module.exports);
|
|
72
73
|
__reExport(client_exports, require("./transformMultiColumnToSingleColumn"), module.exports);
|
|
@@ -100,6 +101,7 @@ __reExport(client_exports, require("./liquidjs"), module.exports);
|
|
|
100
101
|
...require("./i18n"),
|
|
101
102
|
...require("./isPortalInBody"),
|
|
102
103
|
...require("./parseHTML"),
|
|
104
|
+
...require("./sanitize-rich-text-html"),
|
|
103
105
|
...require("./uid"),
|
|
104
106
|
...require("./url"),
|
|
105
107
|
...require("./transformMultiColumnToSingleColumn"),
|
package/lib/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export * from './url';
|
|
|
46
46
|
export * from './variable-usage';
|
|
47
47
|
export * from './wrap-middleware';
|
|
48
48
|
export * from './run-sql';
|
|
49
|
+
export * from './sanitize-rich-text-html';
|
|
49
50
|
export * from './liquidjs';
|
|
50
51
|
export * from './server-request';
|
|
51
52
|
export * from './storage-path';
|
package/lib/index.js
CHANGED
|
@@ -82,6 +82,7 @@ __reExport(src_exports, require("./url"), module.exports);
|
|
|
82
82
|
__reExport(src_exports, require("./variable-usage"), module.exports);
|
|
83
83
|
__reExport(src_exports, require("./wrap-middleware"), module.exports);
|
|
84
84
|
__reExport(src_exports, require("./run-sql"), module.exports);
|
|
85
|
+
__reExport(src_exports, require("./sanitize-rich-text-html"), module.exports);
|
|
85
86
|
__reExport(src_exports, require("./liquidjs"), module.exports);
|
|
86
87
|
__reExport(src_exports, require("./server-request"), module.exports);
|
|
87
88
|
__reExport(src_exports, require("./storage-path"), module.exports);
|
|
@@ -127,6 +128,7 @@ __reExport(src_exports, require("./storage-path"), module.exports);
|
|
|
127
128
|
...require("./variable-usage"),
|
|
128
129
|
...require("./wrap-middleware"),
|
|
129
130
|
...require("./run-sql"),
|
|
131
|
+
...require("./sanitize-rich-text-html"),
|
|
130
132
|
...require("./liquidjs"),
|
|
131
133
|
...require("./server-request"),
|
|
132
134
|
...require("./storage-path")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sanitizeRichTextHtml(value: string): any;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name in all)
|
|
19
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
var __copyProps = (to, from, except, desc) => {
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(from))
|
|
24
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var sanitize_rich_text_html_exports = {};
|
|
39
|
+
__export(sanitize_rich_text_html_exports, {
|
|
40
|
+
sanitizeRichTextHtml: () => sanitizeRichTextHtml
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(sanitize_rich_text_html_exports);
|
|
43
|
+
var import_sanitize_html = __toESM(require("sanitize-html"));
|
|
44
|
+
const imageDataUrlPattern = /^data:image\/(?:gif|jpe?g|png|webp);base64,[a-z\d+/=\s]+$/i;
|
|
45
|
+
const dimensionPattern = /^(?:\d{1,4}(?:\.\d+)?(?:px)?|(?:100|[1-9]?\d)(?:\.\d+)?%)$/;
|
|
46
|
+
const imageStyleDimensionPattern = /^(?:\d{1,4}(?:\.\d+)?px|(?:100|[1-9]?\d)(?:\.\d+)?%)$/;
|
|
47
|
+
function sanitizeLinkAttributes(attribs) {
|
|
48
|
+
const nextAttributes = { ...attribs };
|
|
49
|
+
if (nextAttributes.target && !["_blank", "_self"].includes(nextAttributes.target)) {
|
|
50
|
+
delete nextAttributes.target;
|
|
51
|
+
}
|
|
52
|
+
if (nextAttributes.target === "_blank") {
|
|
53
|
+
nextAttributes.rel = "noopener noreferrer";
|
|
54
|
+
} else {
|
|
55
|
+
delete nextAttributes.rel;
|
|
56
|
+
}
|
|
57
|
+
return nextAttributes;
|
|
58
|
+
}
|
|
59
|
+
__name(sanitizeLinkAttributes, "sanitizeLinkAttributes");
|
|
60
|
+
function sanitizeImageAttributes(attribs) {
|
|
61
|
+
var _a;
|
|
62
|
+
const nextAttributes = { ...attribs };
|
|
63
|
+
if (((_a = nextAttributes.src) == null ? void 0 : _a.trim().toLowerCase().startsWith("data:")) && !imageDataUrlPattern.test(nextAttributes.src)) {
|
|
64
|
+
delete nextAttributes.src;
|
|
65
|
+
}
|
|
66
|
+
for (const dimension of ["width", "height"]) {
|
|
67
|
+
if (nextAttributes[dimension] && !dimensionPattern.test(nextAttributes[dimension])) {
|
|
68
|
+
delete nextAttributes[dimension];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return nextAttributes;
|
|
72
|
+
}
|
|
73
|
+
__name(sanitizeImageAttributes, "sanitizeImageAttributes");
|
|
74
|
+
const richTextSanitizeOptions = {
|
|
75
|
+
allowedTags: [
|
|
76
|
+
"a",
|
|
77
|
+
"b",
|
|
78
|
+
"blockquote",
|
|
79
|
+
"br",
|
|
80
|
+
"em",
|
|
81
|
+
"h1",
|
|
82
|
+
"h2",
|
|
83
|
+
"h3",
|
|
84
|
+
"h4",
|
|
85
|
+
"h5",
|
|
86
|
+
"h6",
|
|
87
|
+
"i",
|
|
88
|
+
"img",
|
|
89
|
+
"li",
|
|
90
|
+
"ol",
|
|
91
|
+
"p",
|
|
92
|
+
"s",
|
|
93
|
+
"span",
|
|
94
|
+
"strike",
|
|
95
|
+
"strong",
|
|
96
|
+
"u",
|
|
97
|
+
"ul"
|
|
98
|
+
],
|
|
99
|
+
allowedAttributes: {
|
|
100
|
+
a: ["href", "target", "rel"],
|
|
101
|
+
img: ["src", "alt", "title", "width", "height", "style"],
|
|
102
|
+
span: ["style"]
|
|
103
|
+
},
|
|
104
|
+
allowedClasses: {
|
|
105
|
+
blockquote: [/^ql-indent-[1-9]$/],
|
|
106
|
+
h1: [/^ql-indent-[1-9]$/],
|
|
107
|
+
h2: [/^ql-indent-[1-9]$/],
|
|
108
|
+
h3: [/^ql-indent-[1-9]$/],
|
|
109
|
+
h4: [/^ql-indent-[1-9]$/],
|
|
110
|
+
h5: [/^ql-indent-[1-9]$/],
|
|
111
|
+
h6: [/^ql-indent-[1-9]$/],
|
|
112
|
+
li: [/^ql-indent-[1-9]$/],
|
|
113
|
+
p: [/^ql-indent-[1-9]$/]
|
|
114
|
+
},
|
|
115
|
+
allowedStyles: {
|
|
116
|
+
img: {
|
|
117
|
+
height: [imageStyleDimensionPattern],
|
|
118
|
+
width: [imageStyleDimensionPattern]
|
|
119
|
+
},
|
|
120
|
+
span: {
|
|
121
|
+
"font-size": [/^(?:12|14|16|18|20|24|32|48)px$/]
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
allowedSchemes: ["http", "https", "mailto", "tel"],
|
|
125
|
+
allowedSchemesByTag: {
|
|
126
|
+
img: ["http", "https", "data"]
|
|
127
|
+
},
|
|
128
|
+
allowProtocolRelative: false,
|
|
129
|
+
transformTags: {
|
|
130
|
+
a(tagName, attribs) {
|
|
131
|
+
return { tagName, attribs: sanitizeLinkAttributes(attribs) };
|
|
132
|
+
},
|
|
133
|
+
img(tagName, attribs) {
|
|
134
|
+
return { tagName, attribs: sanitizeImageAttributes(attribs) };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
function sanitizeRichTextHtml(value) {
|
|
139
|
+
return (0, import_sanitize_html.default)(value, richTextSanitizeOptions);
|
|
140
|
+
}
|
|
141
|
+
__name(sanitizeRichTextHtml, "sanitizeRichTextHtml");
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
sanitizeRichTextHtml
|
|
145
|
+
});
|
package/lib/storage-path.js
CHANGED
|
@@ -43,12 +43,19 @@ __export(storage_path_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(storage_path_exports);
|
|
45
45
|
var import_path = __toESM(require("path"));
|
|
46
|
+
function resolveDefaultStorageRoot() {
|
|
47
|
+
if (import_path.default.basename(process.cwd()) === "source") {
|
|
48
|
+
return import_path.default.resolve(process.cwd(), "..", "storage");
|
|
49
|
+
}
|
|
50
|
+
return import_path.default.resolve(process.cwd(), "storage");
|
|
51
|
+
}
|
|
52
|
+
__name(resolveDefaultStorageRoot, "resolveDefaultStorageRoot");
|
|
46
53
|
function resolveStorageRoot() {
|
|
47
54
|
const raw = process.env.STORAGE_PATH;
|
|
48
55
|
if (raw) {
|
|
49
56
|
return import_path.default.isAbsolute(raw) ? raw : import_path.default.resolve(process.cwd(), raw);
|
|
50
57
|
}
|
|
51
|
-
return
|
|
58
|
+
return resolveDefaultStorageRoot();
|
|
52
59
|
}
|
|
53
60
|
__name(resolveStorageRoot, "resolveStorageRoot");
|
|
54
61
|
function storagePathJoin(...segments) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-alpha.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"liquidjs": "^10.23.0",
|
|
20
20
|
"multer": "^2.1.1",
|
|
21
21
|
"object-path": "^0.11.8",
|
|
22
|
+
"sanitize-html": "2.17.5",
|
|
22
23
|
"ses": "^1.14.0"
|
|
23
24
|
},
|
|
24
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "82ecd3aed067e4cc98c32e7a0039b6e55cee76a7"
|
|
25
26
|
}
|