@web-widget/purify 1.41.1 → 1.42.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/purify.d.ts +5 -10
- package/dist/purify.js +45 -32
- package/package.json +1 -1
package/dist/purify.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* https://github.com/component/escape-html/blob/master/index.js
|
|
4
|
-
* Copyright(c) 2012-2013 TJ Holowaychuk
|
|
5
|
-
* Copyright(c) 2015 Andreas Lubbe
|
|
6
|
-
* Copyright(c) 2015 Tiancheng "Timothy" Gu
|
|
7
|
-
* MIT Licensed
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Escape special characters in the given string of text.
|
|
2
|
+
* Escape special characters in the given string of html.
|
|
11
3
|
*/
|
|
12
4
|
declare function escapeHtml(string: string): string;
|
|
13
5
|
|
|
14
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Escape special characters in the given string of json.
|
|
8
|
+
*/
|
|
9
|
+
declare function escapeJson(string: string): string;
|
|
15
10
|
|
|
16
11
|
export { escapeHtml, escapeJson };
|
package/dist/purify.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
function escapeHtml(string) {
|
|
1
|
+
// src/replace.ts
|
|
2
|
+
function replace(string, matchRegExp, replace2) {
|
|
4
3
|
const str = "" + string;
|
|
5
|
-
const match =
|
|
4
|
+
const match = matchRegExp.exec(str);
|
|
6
5
|
if (!match) {
|
|
7
6
|
return str;
|
|
8
7
|
}
|
|
@@ -11,24 +10,9 @@ function escapeHtml(string) {
|
|
|
11
10
|
let index = 0;
|
|
12
11
|
let lastIndex = 0;
|
|
13
12
|
for (index = match.index; index < str.length; index++) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
break;
|
|
18
|
-
case 38:
|
|
19
|
-
escape = "&";
|
|
20
|
-
break;
|
|
21
|
-
case 39:
|
|
22
|
-
escape = "'";
|
|
23
|
-
break;
|
|
24
|
-
case 60:
|
|
25
|
-
escape = "<";
|
|
26
|
-
break;
|
|
27
|
-
case 62:
|
|
28
|
-
escape = ">";
|
|
29
|
-
break;
|
|
30
|
-
default:
|
|
31
|
-
continue;
|
|
13
|
+
escape = replace2(str.charCodeAt(index));
|
|
14
|
+
if (!escape) {
|
|
15
|
+
continue;
|
|
32
16
|
}
|
|
33
17
|
if (lastIndex !== index) {
|
|
34
18
|
html += str.substring(lastIndex, index);
|
|
@@ -39,17 +23,46 @@ function escapeHtml(string) {
|
|
|
39
23
|
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
|
|
40
24
|
}
|
|
41
25
|
|
|
26
|
+
// src/html.ts
|
|
27
|
+
var MATCH_HTML_REGEXP = /["'&<>]/;
|
|
28
|
+
function escapeHtml(string) {
|
|
29
|
+
return replace(string, MATCH_HTML_REGEXP, (code) => {
|
|
30
|
+
switch (code) {
|
|
31
|
+
case 34:
|
|
32
|
+
return """;
|
|
33
|
+
case 38:
|
|
34
|
+
return "&";
|
|
35
|
+
case 39:
|
|
36
|
+
return "'";
|
|
37
|
+
case 60:
|
|
38
|
+
return "<";
|
|
39
|
+
case 62:
|
|
40
|
+
return ">";
|
|
41
|
+
default:
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
// src/json.ts
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
var MARCH_JSON_REGEX = /[&><\u2028\u2029]/;
|
|
49
|
+
function escapeJson(string) {
|
|
50
|
+
return replace(string, MARCH_JSON_REGEX, (code) => {
|
|
51
|
+
switch (code) {
|
|
52
|
+
case 38:
|
|
53
|
+
return "\\u0026";
|
|
54
|
+
case 62:
|
|
55
|
+
return "\\u003e";
|
|
56
|
+
case 60:
|
|
57
|
+
return "\\u003c";
|
|
58
|
+
case 8232:
|
|
59
|
+
return "\\u2028";
|
|
60
|
+
case 8233:
|
|
61
|
+
return "\\u2029";
|
|
62
|
+
default:
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
53
66
|
}
|
|
54
67
|
export {
|
|
55
68
|
escapeHtml,
|