diff --git a/ts/test-both/processDataMessage_test.ts b/ts/test-both/processDataMessage_test.ts index 85b7a68cd..91226a380 100644 --- a/ts/test-both/processDataMessage_test.ts +++ b/ts/test-both/processDataMessage_test.ts @@ -3,6 +3,7 @@ /* eslint-disable no-restricted-syntax */ import { assert } from 'chai'; +import Long from 'long'; import { processDataMessage, @@ -49,6 +50,24 @@ describe('processDataMessage', () => { assert.deepStrictEqual(out.attachments, [PROCESSED_ATTACHMENT]); }); + it('should process attachments with 0 cdnId', async () => { + const out = await check({ + attachments: [ + { + ...UNPROCESSED_ATTACHMENT, + cdnId: new Long(0), + }, + ], + }); + + assert.deepStrictEqual(out.attachments, [ + { + ...PROCESSED_ATTACHMENT, + cdnId: undefined, + }, + ]); + }); + it('should throw on too many attachments', async () => { const attachments: Array = []; for (let i = 0; i < ATTACHMENT_MAX + 1; i += 1) { diff --git a/ts/textsecure/processDataMessage.ts b/ts/textsecure/processDataMessage.ts index f018502b5..8307abe6b 100644 --- a/ts/textsecure/processDataMessage.ts +++ b/ts/textsecure/processDataMessage.ts @@ -43,10 +43,14 @@ export function processAttachment( if (!attachment) { return undefined; } + + const { cdnId } = attachment; + const hasCdnId = cdnId instanceof Long ? !cdnId.isZero() : Boolean(cdnId); + return { ...shallowDropNull(attachment), - cdnId: attachment.cdnId ? attachment.cdnId.toString() : undefined, + cdnId: hasCdnId ? String(cdnId) : undefined, key: attachment.key ? Bytes.toBase64(attachment.key) : undefined, digest: attachment.digest ? Bytes.toBase64(attachment.digest) : undefined, };