Skip to content

Commit f2e9b16

Browse files
utanapishtimutanapishtim
and
utanapishtim
authored
Bugfix: File Cache Equality Check Incorrectly Compares Dates (#1544)
* refactors to correctly check if dates are equal * Update attachments.js * fixes lint error --------- Co-authored-by: utanapishtim <[email protected]>
1 parent 9e5dfcd commit f2e9b16

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/mixins/attachments.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function isEqual(a, b) {
109109
a.Subtype === b.Subtype &&
110110
a.Params.CheckSum.toString() === b.Params.CheckSum.toString() &&
111111
a.Params.Size === b.Params.Size &&
112-
a.Params.CreationDate === b.Params.CreationDate &&
113-
a.Params.ModDate === b.Params.ModDate
112+
a.Params.CreationDate.getTime() === b.Params.CreationDate.getTime() &&
113+
a.Params.ModDate.getTime() === b.Params.ModDate.getTime()
114114
);
115115
}

tests/unit/attachments.spec.js

+35
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,41 @@ describe('file', () => {
192192
(file2.txt) 11 0 R
193193
]
194194
>>
195+
>>`
196+
]);
197+
});
198+
199+
test('attach the same file multiple times', () => {
200+
const docData = logData(document);
201+
202+
document.file(Buffer.from('example text'), {
203+
name: 'file1.txt',
204+
creationDate: date,
205+
modifiedDate: date
206+
});
207+
document.file(Buffer.from('example text'), {
208+
name: 'file1.txt',
209+
creationDate: new Date(date),
210+
modifiedDate: new Date(date)
211+
});
212+
document.end();
213+
214+
const numFiles = docData.filter((str) => typeof str === 'string' && str.startsWith('<<\n/Type /EmbeddedFile\n'))
215+
216+
expect(numFiles.length).toEqual(1)
217+
218+
expect(docData).toContainChunk([
219+
`2 0 obj`,
220+
`<<
221+
/Dests <<
222+
/Names [
223+
]
224+
>>
225+
/EmbeddedFiles <<
226+
/Names [
227+
(file1.txt) 10 0 R
228+
]
229+
>>
195230
>>`
196231
]);
197232
});

0 commit comments

Comments
 (0)