module-develop-kit 1.2.2 → 1.2.3
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/main.d.ts +4 -3
- package/dist/src/shield/url-sanitize.js +21 -21
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -57,9 +57,8 @@ export declare function detectFileByExtension(file: File, _allowedExtensions: TM
|
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* 检测文件真实类型并验证 MIME 类型
|
|
60
|
-
*
|
|
61
60
|
* @param file 要检测的文件
|
|
62
|
-
* @param _allowedMimes 允许的MIME类型列表
|
|
61
|
+
* @param _allowedMimes 允许的MIME类型列表 支持单个或者数组。单个支持使用,分割,支持通配符
|
|
63
62
|
* @param options 检测选项
|
|
64
63
|
* @returns 检测结果
|
|
65
64
|
*/
|
|
@@ -347,6 +346,8 @@ export declare function isValidFile(file: File, maxSize?: number): Promise<IFile
|
|
|
347
346
|
|
|
348
347
|
/**
|
|
349
348
|
* 便捷方法: 检测是否为图片文件(基于 MIME 类型)
|
|
349
|
+
* @file 要检测的文件
|
|
350
|
+
* @maxSize 文件最大尺寸
|
|
350
351
|
*/
|
|
351
352
|
export declare function isValidImage(file: File, maxSize?: number): Promise<IFileDetectionResult>;
|
|
352
353
|
|
|
@@ -376,7 +377,7 @@ export declare interface IUrlSanitizeOptions {
|
|
|
376
377
|
*/
|
|
377
378
|
fallbackUrl?: string;
|
|
378
379
|
/**
|
|
379
|
-
* 是否严格模式,严格模式下只允许 http/https,默认
|
|
380
|
+
* 是否严格模式,严格模式下只允许 http/https,默认 true
|
|
380
381
|
*/
|
|
381
382
|
strictMode?: boolean;
|
|
382
383
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const i = ["http:", "https:", "mailto:", "tel:", "sms:", "ftp:", "ftps:"],
|
|
1
|
+
const i = ["http:", "https:", "mailto:", "tel:", "sms:", "ftp:", "ftps:"], n = [
|
|
2
2
|
// eslint-disable-next-line no-script-url
|
|
3
3
|
"javascript:",
|
|
4
4
|
"data:",
|
|
@@ -7,11 +7,11 @@ const i = ["http:", "https:", "mailto:", "tel:", "sms:", "ftp:", "ftps:"], o = [
|
|
|
7
7
|
"about:",
|
|
8
8
|
"blob:"
|
|
9
9
|
];
|
|
10
|
-
function
|
|
10
|
+
function c(t) {
|
|
11
11
|
return t.replace(/[-]/g, "").replace(/\s+/g, "").trim();
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
13
|
+
function a(t) {
|
|
14
|
+
const r = t.toLowerCase();
|
|
15
15
|
return [
|
|
16
16
|
/javascript:/i,
|
|
17
17
|
/data:text\/html/i,
|
|
@@ -25,35 +25,35 @@ function n(t) {
|
|
|
25
25
|
// URL 编码的 javascript
|
|
26
26
|
/\\u006a\\u0061\\u0076\\u0061/i
|
|
27
27
|
// Unicode 编码
|
|
28
|
-
].some((s) => s.test(
|
|
28
|
+
].some((s) => s.test(r) || s.test(t));
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function l(t, r = {}) {
|
|
31
31
|
if (!t || typeof t != "string")
|
|
32
32
|
return !1;
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
33
|
+
const e = t.trim();
|
|
34
|
+
if (!e)
|
|
35
35
|
return !1;
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
38
|
-
const s =
|
|
39
|
-
if (
|
|
36
|
+
if (e.startsWith("/") || e.startsWith("./") || e.startsWith("../"))
|
|
37
|
+
return r.allowRelative === !1 ? !1 : !a(e);
|
|
38
|
+
const s = c(e);
|
|
39
|
+
if (a(s))
|
|
40
40
|
return !1;
|
|
41
41
|
try {
|
|
42
|
-
const
|
|
43
|
-
return
|
|
42
|
+
const o = new URL(s, "http://example.com").protocol.toLowerCase();
|
|
43
|
+
return r.strictMode ?? !0 ? ["http:", "https:", ...r.extraSafeProtocols || []].includes(o) : n.includes(o) ? !1 : [...i, ...r.extraSafeProtocols || []].includes(o);
|
|
44
44
|
} catch {
|
|
45
45
|
return !1;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
function f(t,
|
|
49
|
-
const
|
|
50
|
-
return
|
|
48
|
+
function f(t, r = {}) {
|
|
49
|
+
const e = r.fallbackUrl || "#";
|
|
50
|
+
return l(t, r) ? t.trim() : e;
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
return t.map((
|
|
52
|
+
function P(t, r = {}) {
|
|
53
|
+
return t.map((e) => f(e, r));
|
|
54
54
|
}
|
|
55
55
|
export {
|
|
56
|
-
|
|
56
|
+
l as isUrlSafe,
|
|
57
57
|
f as sanitizeUrl,
|
|
58
|
-
|
|
58
|
+
P as sanitizeUrls
|
|
59
59
|
};
|