minimalistic-server 0.0.54 → 0.0.55
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/index.mjs +67 -12
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -36,6 +36,70 @@ function safePrint(data, isError = false) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
const escapeHtmlMap = {
|
|
40
|
+
"&": "&",
|
|
41
|
+
"<": "<",
|
|
42
|
+
">": ">",
|
|
43
|
+
'"': """,
|
|
44
|
+
"'": "'",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const unescapeHtmlMap = {
|
|
48
|
+
" ": "\u00A0",
|
|
49
|
+
"<": "<",
|
|
50
|
+
">": ">",
|
|
51
|
+
"&": "&",
|
|
52
|
+
""": "\"",
|
|
53
|
+
"'": "'",
|
|
54
|
+
"¢": "¢",
|
|
55
|
+
"£": "£",
|
|
56
|
+
"¥": "¥",
|
|
57
|
+
"€": "€",
|
|
58
|
+
"©": "©",
|
|
59
|
+
"®": "®",
|
|
60
|
+
"™": "™",
|
|
61
|
+
|
|
62
|
+
"…": "…",
|
|
63
|
+
"–": "–",
|
|
64
|
+
"—": "—",
|
|
65
|
+
"‘": "‘",
|
|
66
|
+
"’": "’",
|
|
67
|
+
"“": "“",
|
|
68
|
+
"”": "”",
|
|
69
|
+
"«": "«",
|
|
70
|
+
"»": "»",
|
|
71
|
+
|
|
72
|
+
"×": "×",
|
|
73
|
+
"÷": "÷",
|
|
74
|
+
"±": "±",
|
|
75
|
+
"−": "−",
|
|
76
|
+
"²": "²",
|
|
77
|
+
"³": "³",
|
|
78
|
+
"½": "½",
|
|
79
|
+
"¼": "¼",
|
|
80
|
+
"¾": "¾",
|
|
81
|
+
|
|
82
|
+
"°": "°",
|
|
83
|
+
"µ": "µ",
|
|
84
|
+
"¶": "¶",
|
|
85
|
+
"§": "§",
|
|
86
|
+
"·": "·",
|
|
87
|
+
"•": "•",
|
|
88
|
+
|
|
89
|
+
"α": "α",
|
|
90
|
+
"β": "β",
|
|
91
|
+
"γ": "γ",
|
|
92
|
+
"π": "π",
|
|
93
|
+
"σ": "σ",
|
|
94
|
+
"ω": "ω",
|
|
95
|
+
"Α": "Α",
|
|
96
|
+
"Β": "Β",
|
|
97
|
+
"Γ": "Γ",
|
|
98
|
+
"Π": "Π",
|
|
99
|
+
"Σ": "Σ",
|
|
100
|
+
"Ω": "Ω"
|
|
101
|
+
}
|
|
102
|
+
|
|
39
103
|
const mimeTypes = {
|
|
40
104
|
"123": "application/vnd.lotus-1-2-3",
|
|
41
105
|
"3dml": "text/vnd.in3d.3dml",
|
|
@@ -2105,22 +2169,13 @@ export function serve(routes, port = 80, staticFileDirectoryOrDirectories = null
|
|
|
2105
2169
|
|
|
2106
2170
|
}
|
|
2107
2171
|
|
|
2108
|
-
export function escapeHtml(
|
|
2109
|
-
return
|
|
2110
|
-
.replace(/&/gm, "&")
|
|
2111
|
-
.replace(/</gm, "<")
|
|
2112
|
-
.replace(/>/gm, ">")
|
|
2113
|
-
.replace(/"/gm, """)
|
|
2114
|
-
.replace(/'/gm, "'") ?? '';
|
|
2172
|
+
export function escapeHtml(str) {
|
|
2173
|
+
return str?.toString().replace(/[&<>"']/gm, (c) => escapeHtmlMap[c]) ?? '';
|
|
2115
2174
|
}
|
|
2116
2175
|
|
|
2117
2176
|
export function unescapeHtml(htmlStr) {
|
|
2118
2177
|
return htmlStr?.toString()
|
|
2119
|
-
.replace(/&
|
|
2120
|
-
.replace(/</gm, "<")
|
|
2121
|
-
.replace(/>/gm, ">")
|
|
2122
|
-
.replace(/"/gm, '"')
|
|
2123
|
-
.replace(/'/gm, "'") ?? '';
|
|
2178
|
+
.replace(/&(?:#(\d+|x[\dA-Fa-f]+)|([^;]+));/gm, (entity, digits, entityName) => unescapeHtmlMap[entity] ?? entityName ?? String.fromCharCode("0" + digits));
|
|
2124
2179
|
}
|
|
2125
2180
|
|
|
2126
2181
|
export function unserve(port = 80) {
|