minimalistic-server 0.0.54 → 0.0.56

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.
Files changed (2) hide show
  1. package/index.mjs +71 -16
  2. 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
+ "<": "&lt;",
42
+ ">": "&gt;",
43
+ '"': "&quot;",
44
+ "'": "&#39;",
45
+ }
46
+
47
+ const unescapeHtmlMap = {
48
+ "&nbsp;": "\u00A0",
49
+ "&lt;": "<",
50
+ "&gt;": ">",
51
+ "&amp;": "&",
52
+ "&quot;": "\"",
53
+ "&apos;": "'",
54
+ "&cent;": "¢",
55
+ "&pound;": "£",
56
+ "&yen;": "¥",
57
+ "&euro;": "€",
58
+ "&copy;": "©",
59
+ "&reg;": "®",
60
+ "&trade;": "™",
61
+
62
+ "&hellip;": "…",
63
+ "&ndash;": "–",
64
+ "&mdash;": "—",
65
+ "&lsquo;": "‘",
66
+ "&rsquo;": "’",
67
+ "&ldquo;": "“",
68
+ "&rdquo;": "”",
69
+ "&laquo;": "«",
70
+ "&raquo;": "»",
71
+
72
+ "&times;": "×",
73
+ "&divide;": "÷",
74
+ "&plusmn;": "±",
75
+ "&minus;": "−",
76
+ "&sup2;": "²",
77
+ "&sup3;": "³",
78
+ "&frac12;": "½",
79
+ "&frac14;": "¼",
80
+ "&frac34;": "¾",
81
+
82
+ "&deg;": "°",
83
+ "&micro;": "µ",
84
+ "&para;": "¶",
85
+ "&sect;": "§",
86
+ "&middot;": "·",
87
+ "&bull;": "•",
88
+
89
+ "&alpha;": "α",
90
+ "&beta;": "β",
91
+ "&gamma;": "γ",
92
+ "&pi;": "π",
93
+ "&sigma;": "σ",
94
+ "&omega;": "ω",
95
+ "&Alpha;": "Α",
96
+ "&Beta;": "Β",
97
+ "&Gamma;": "Γ",
98
+ "&Pi;": "Π",
99
+ "&Sigma;": "Σ",
100
+ "&Omega;": "Ω"
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(htmlStr) {
2109
- return htmlStr?.toString()
2110
- .replace(/&/gm, "&amp;")
2111
- .replace(/</gm, "&lt;")
2112
- .replace(/>/gm, "&gt;")
2113
- .replace(/"/gm, "&quot;")
2114
- .replace(/'/gm, "&#39;") ?? '';
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(/&amp;/gm, "&")
2120
- .replace(/&lt;/gm, "<")
2121
- .replace(/&gt;/gm, ">")
2122
- .replace(/&quot;/gm, '"')
2123
- .replace(/&#39;/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) {
@@ -2251,13 +2306,13 @@ function normalizeRoutes(routes, handleServerError) {
2251
2306
  flattenRecursively(root[prop], newPath, preMiddlewares, postMiddlewares);
2252
2307
  }
2253
2308
  } else if (typeof root === 'function') {
2254
- flatten[path] = wrapInMiddlewares(root, preMiddlewares, postMiddlewares, handleServerError);
2309
+ setObjectProperty(flatten, path, wrapInMiddlewares(root, preMiddlewares, postMiddlewares, handleServerError));
2255
2310
  }
2256
2311
  }
2257
2312
 
2258
2313
  flattenRecursively(routes);
2259
2314
 
2260
- const result = {};
2315
+ const result = Object.create(null);
2261
2316
 
2262
2317
  for (const route in flatten) {
2263
2318
  const split = route.split('/').filter(x => x);
@@ -2273,13 +2328,13 @@ function normalizeRoutes(routes, handleServerError) {
2273
2328
 
2274
2329
  for (const fragment of split) {
2275
2330
  if (!parent[fragment]) {
2276
- parent[fragment] = { __proto__: null };
2331
+ setObjectProperty(parent, fragment, Object.create(null));
2277
2332
  }
2278
2333
 
2279
2334
  parent = parent[fragment];
2280
2335
  }
2281
2336
 
2282
- parent[`/${method}/`] = flatten[route];
2337
+ setObjectProperty(parent, `/${method}/`, flatten[route]);
2283
2338
  }
2284
2339
 
2285
2340
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimalistic-server",
3
- "version": "0.0.54",
3
+ "version": "0.0.56",
4
4
  "engines" : {
5
5
  "npm" : ">=8.6.0",
6
6
  "node" : ">=22.0.0"