Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: File Cache Equality Check Incorrectly Compares Dates #1544

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading