From 27f53bfa5140081db818984d274190b4c394e98f Mon Sep 17 00:00:00 2001 From: LightningNeko <80431773+LightningNeko@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:13:53 +0200 Subject: [PATCH] fix: xml-not-well-formed on +255 size lists (#1762) --- src/WABinary/encode.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/WABinary/encode.ts b/src/WABinary/encode.ts index 1f3a5e4..92cb02e 100644 --- a/src/WABinary/encode.ts +++ b/src/WABinary/encode.ts @@ -22,6 +22,9 @@ export const encodeBinaryNode = ( const pushBytes = (bytes: Uint8Array | Buffer | number[]) => ( bytes.forEach (b => buffer.push(b)) ) + const pushInt16 = (value: number) => { + pushBytes([(value >> 8) & 0xff, value & 0xff]) + } const pushInt20 = (value: number) => ( pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]) ) @@ -194,7 +197,8 @@ export const encodeBinaryNode = ( } else if(listSize < 256) { pushBytes([TAGS.LIST_8, listSize]) } else { - pushBytes([TAGS.LIST_16, listSize]) + pushByte(TAGS.LIST_16) + pushInt16(listSize) } }