diff --git a/lib/mixins/attachments.js b/lib/mixins/attachments.js index 862fd9a8..412f9563 100644 --- a/lib/mixins/attachments.js +++ b/lib/mixins/attachments.js @@ -109,7 +109,7 @@ function isEqual(a, b) { a.Subtype === b.Subtype && a.Params.CheckSum.toString() === b.Params.CheckSum.toString() && a.Params.Size === b.Params.Size && - a.Params.CreationDate === b.Params.CreationDate && - a.Params.ModDate === b.Params.ModDate + a.Params.CreationDate.getTime() === b.Params.CreationDate.getTime() && + a.Params.ModDate.getTime() === b.Params.ModDate.getTime() ); } diff --git a/tests/unit/attachments.spec.js b/tests/unit/attachments.spec.js index a2386583..86bc8b2a 100644 --- a/tests/unit/attachments.spec.js +++ b/tests/unit/attachments.spec.js @@ -192,6 +192,41 @@ describe('file', () => { (file2.txt) 11 0 R ] >> +>>` + ]); + }); + + test('attach the same file multiple times', () => { + const docData = logData(document); + + document.file(Buffer.from('example text'), { + name: 'file1.txt', + creationDate: date, + modifiedDate: date + }); + document.file(Buffer.from('example text'), { + name: 'file1.txt', + creationDate: new Date(date), + modifiedDate: new Date(date) + }); + document.end(); + + const numFiles = docData.filter((str) => typeof str === 'string' && str.startsWith('<<\n/Type /EmbeddedFile\n')) + + expect(numFiles.length).toEqual(1) + + expect(docData).toContainChunk([ + `2 0 obj`, + `<< +/Dests << + /Names [ +] +>> +/EmbeddedFiles << + /Names [ + (file1.txt) 10 0 R +] +>> >>` ]); });