nox-mem 3.5.0 → 3.5.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/dist/api-server.js +1 -12
- package/dist/lib/query-params.js +19 -0
- package/package.json +1 -1
package/dist/api-server.js
CHANGED
|
@@ -16,6 +16,7 @@ import { getVaultFacts } from "./lib/spo-injection.js";
|
|
|
16
16
|
import { execFileSync } from "child_process";
|
|
17
17
|
import { applyCorsHeaders, handlePreflight } from "./api/cors.js";
|
|
18
18
|
import { safeErrorMessage } from "./lib/api/safe-error-message.js";
|
|
19
|
+
import { parseQuery } from "./lib/query-params.js";
|
|
19
20
|
import { registerWireUpRoutes } from "./api/wire-up.js";
|
|
20
21
|
import { handleBrief } from "./api/brief.js";
|
|
21
22
|
import { parseTemporalFilter, TemporalParseError } from "./lib/dates.js";
|
|
@@ -33,18 +34,6 @@ function json(res, data, status = 200) {
|
|
|
33
34
|
});
|
|
34
35
|
res.end(JSON.stringify(data));
|
|
35
36
|
}
|
|
36
|
-
function parseQuery(url) {
|
|
37
|
-
const idx = url.indexOf("?");
|
|
38
|
-
if (idx === -1)
|
|
39
|
-
return {};
|
|
40
|
-
const params = {};
|
|
41
|
-
for (const part of url.substring(idx + 1).split("&")) {
|
|
42
|
-
const [k, v] = part.split("=");
|
|
43
|
-
if (k)
|
|
44
|
-
params[decodeURIComponent(k)] = decodeURIComponent(v || "");
|
|
45
|
-
}
|
|
46
|
-
return params;
|
|
47
|
-
}
|
|
48
37
|
function readBody(req, limit = 65536) {
|
|
49
38
|
return new Promise((resolve, reject) => {
|
|
50
39
|
let data = "";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Query-string parsing for the HTTP API.
|
|
2
|
+
//
|
|
3
|
+
// The hand-rolled split("&") / split("=") parser this replaces had three defects:
|
|
4
|
+
// "+" stayed a literal plus (URLSearchParams, and so most JS clients, encode a
|
|
5
|
+
// space as "+", which turned `salience formula` into a search for
|
|
6
|
+
// `salience+formula`); a value containing "=" was truncated at it; and keys went
|
|
7
|
+
// into a plain object, so `__proto__` / `hasOwnProperty` could collide with
|
|
8
|
+
// Object.prototype. URLSearchParams handles the first two and never throws on a
|
|
9
|
+
// malformed "%" escape. For the third, the prototype-reaching keys are dropped
|
|
10
|
+
// (no route reads them) and the object has no prototype as a second layer.
|
|
11
|
+
const RESERVED_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
12
|
+
export function parseQuery(url) {
|
|
13
|
+
const idx = url.indexOf("?");
|
|
14
|
+
const pairs = idx === -1 ? [] : [...new URLSearchParams(url.substring(idx + 1))];
|
|
15
|
+
// fromEntries defines own data properties (a later duplicate key wins, as
|
|
16
|
+
// before) instead of assigning through a computed key.
|
|
17
|
+
const params = Object.fromEntries(pairs.filter(([k]) => k && !RESERVED_KEYS.has(k)));
|
|
18
|
+
return Object.setPrototypeOf(params, null);
|
|
19
|
+
}
|