Skip to content
Open
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
14 changes: 14 additions & 0 deletions src/main/downloadsManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ describe('main/downloadsManager', () => {
expect(dl.fileSizes.get('file.txt')).toBe('4242');
});

it('MM-68690 - should not throw when content-disposition header is missing', () => {
const dl = new DownloadsManager({});
const details = {
responseHeaders: {
'content-encoding': ['gzip'],
'x-uncompressed-content-length': ['4242'],
},
};
const cb = jest.fn();
expect(() => dl.webRequestOnHeadersReceivedHandler(details, cb)).not.toThrow();
expect(cb).toHaveBeenCalledWith({});
expect(dl.fileSizes.size).toBe(0);
});

it('should clear the downloads list', () => {
const dl = new DownloadsManager(JSON.stringify(downloadsJson));
dl.clearDownloadsDropDown();
Expand Down
2 changes: 1 addition & 1 deletion src/main/downloadsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class DownloadsManager extends JsonFileManager<DownloadedItems> {
webRequestOnHeadersReceivedHandler = (details: Electron.OnHeadersReceivedListenerDetails, cb: (headersReceivedResponse: Electron.HeadersReceivedResponse) => void) => {
const headers = details.responseHeaders ?? {};

if (headers?.['content-encoding']?.includes('gzip') && headers?.['x-uncompressed-content-length'] && headers?.['content-disposition'].join(';')?.includes('filename=')) {
if (headers?.['content-encoding']?.includes('gzip') && headers?.['x-uncompressed-content-length'] && headers?.['content-disposition']?.join?.(';')?.includes('filename=')) {
const filename = readFilenameFromContentDispositionHeader(headers['content-disposition']);
const fileSize = headers['x-uncompressed-content-length']?.[0] || '0';
if (filename && (!this.fileSizes.has(filename) || this.fileSizes.get(filename)?.toString() !== fileSize)) {
Expand Down
Loading