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

This commit is contained in:
Maurice
2026-11-23 15:53:58 +01:00
parent 907fc95b00
commit 4b6911b51f
2 changed files with 9 additions and 1 deletions
+2 -1
View File
@@ -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');
}
@@ -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');
});
});