mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
fix(plugins): bind a Buffer in the single-array bind form of ctx.db as its bytes
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user