diff --git a/__tests__/sanitization.test.ts b/__tests__/sanitization.test.ts index 96c09bf..de520ca 100644 --- a/__tests__/sanitization.test.ts +++ b/__tests__/sanitization.test.ts @@ -80,6 +80,12 @@ describe('sanitization', () => { expect(format(query, [state])).toEqual(expected) }) + test('formats empty Uint8Array', () => { + const query = 'select 1 from user where state = ?' + const expected = "select 1 from user where state = x''" + expect(format(query, [new Uint8Array([])])).toEqual(expected) + }) + test('escapes double quotes', () => { const query = 'select 1 from user where state = ?' const expected = 'select 1 from user where state = \'\\"a\\"\'' diff --git a/__tests__/text.test.ts b/__tests__/text.test.ts index 9639be2..63733ac 100644 --- a/__tests__/text.test.ts +++ b/__tests__/text.test.ts @@ -42,7 +42,8 @@ describe('text', () => { describe('uint8ArrayToHex', () => { test('converts an array of 8-bit unsigned integers to hex', () => { - expect(uint8ArrayToHex(new Uint8Array([197]))).toEqual('0xc5') + expect(uint8ArrayToHex(new Uint8Array([]))).toEqual("x''") + expect(uint8ArrayToHex(new Uint8Array([197]))).toEqual("x'c5'") }) }) }) diff --git a/src/text.ts b/src/text.ts index 849bf07..222ff27 100644 --- a/src/text.ts +++ b/src/text.ts @@ -15,7 +15,7 @@ export function uint8Array(text: string): Uint8Array { export function uint8ArrayToHex(uint8: Uint8Array): string { const digits = Array.from(uint8).map((i) => i.toString(16).padStart(2, '0')) - return `0x${digits.join('')}` + return `x'${digits.join('')}'` } function bytes(text: string): number[] {