Skip to content

Commit

Permalink
Bugfix: File Cache Equality Check Incorrectly Compares Dates (#1544)
Browse files Browse the repository at this point in the history
* refactors to correctly check if dates are equal

* Update attachments.js

* fixes lint error

---------

Co-authored-by: utanapishtim <[email protected]>
  • Loading branch information
utanapishtim and utanapishtim authored Aug 13, 2024
1 parent 9e5dfcd commit f2e9b16
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/mixins/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
35 changes: 35 additions & 0 deletions tests/unit/attachments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
>>
>>`
]);
});
Expand Down

0 comments on commit f2e9b16

Please sign in to comment.