Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(plugins): bind a Buffer in the single-array bind form of ctx.db as its bytes

Maurice4b6911b51f74
diff --git a/server/src/nest-rpc/rpc-params.ts b/server/src/nest-rpc/rpc-params.ts
index c71c41594..bff7d27aa 100644
--- a/server/src/nest-rpc/rpc-params.ts
+++ b/server/src/nest-rpc/rpc-params.ts
@@ -55,7 +55,8 @@ function reviveBuffer(v: unknown): unknown {
export function asArgs(v: unknown): unknown[] {
if (v == null) return [];
- if (Array.isArray(v)) return v.map(reviveBuffer);
+ // The single-array bind form, args: [[a, b]], carries its Buffers one level down.
+ if (Array.isArray(v)) return v.map((a) => (Array.isArray(a) ? a.map(reviveBuffer) : reviveBuffer(a)));
throw new BadParams('args must be an array');
}
diff --git a/server/tests/unit/nest-rpc/rpc-params.test.ts b/server/tests/unit/nest-rpc/rpc-params.test.ts
index 76ce3624e..b7a504fb4 100644
--- a/server/tests/unit/nest-rpc/rpc-params.test.ts
+++ b/server/tests/unit/nest-rpc/rpc-params.test.ts
@@ -35,4 +35,11 @@ describe('asArgs', () => {
const [op] = asTxOps([{ sql: 'SELECT ?', args: wire }]);
expect(Buffer.isBuffer(op?.args?.[0])).toBe(true);
});
+
+ it('RPCPARAM-005: a Buffer in the single-array bind form is bound as its bytes as well', () => {
+ const wire = JSON.parse(JSON.stringify([[Buffer.from([7, 0]), 'k']]));
+ const [[bytes, key]] = asArgs(wire) as unknown[][];
+ expect(Buffer.isBuffer(bytes) && [...(bytes as Buffer)]).toEqual([7, 0]);
+ expect(key).toBe('k');
+ });
});