diff --git a/lib/processImage.js b/lib/processImage.js index 7fc889d..152cdde 100644 --- a/lib/processImage.js +++ b/lib/processImage.js @@ -365,6 +365,20 @@ module.exports = (options) => { detectedContentType = 'image/png'; } else if (firstChunk[0] === 0x42 && firstChunk[1] === 0x4d) { detectedContentType = 'image/bmp'; + } else if ( + firstChunk[0] === 0x0 && + firstChunk[1] === 0x0 && + firstChunk[2] === 0x1 && + firstChunk[3] === 0x0 + ) { + detectedContentType = 'image/x-icon'; + } else if ( + firstChunk[8] === 0x57 && + firstChunk[9] === 0x45 && + firstChunk[10] === 0x42 && + firstChunk[11] === 0x50 + ) { + detectedContentType = 'image/webp'; } if ( detectedContentType && diff --git a/reallyaico.gif b/reallyaico.gif new file mode 100644 index 0000000..a087fa0 Binary files /dev/null and b/reallyaico.gif differ diff --git a/reallyawebp.png b/reallyawebp.png new file mode 100644 index 0000000..a608fc8 Binary files /dev/null and b/reallyawebp.png differ diff --git a/test/processImage.js b/test/processImage.js index 1c1a289..45bb329 100644 --- a/test/processImage.js +++ b/test/processImage.js @@ -1386,6 +1386,27 @@ describe('express-processimage', () => { beforeEach(() => { config.secondGuessSourceContentType = true; }); + it('should recover gracefully when attempting to process a wrongly named webp', () => { + config.debug = true; + return expect('GET /reallyawebp.png?resize=40,30', 'to yield response', { + headers: { + 'X-Express-Processimage': 'sharp', + }, + body: expect.it('to have metadata satisfying', { + format: 'WEBP', + size: { width: 40, height: 30 }, + }), + }); + }); + it('should return the correct contentType of a wrongly named ico', () => { + config.debug = true; + return expect('GET /reallyaico.gif?metadata', 'to yield response', { + body: { + format: expect.it('to equal', 'ico'), + contentType: expect.it('to equal', 'image/x-icon'), + }, + }); + }); it('should recover gracefully when attempting to process a wrongly named jpeg', () => { config.debug = true; return expect('GET /reallyajpeg.gif?resize=40,35', 'to yield response', { diff --git a/testdata/reallyaico.gif b/testdata/reallyaico.gif new file mode 100644 index 0000000..a087fa0 Binary files /dev/null and b/testdata/reallyaico.gif differ diff --git a/testdata/reallyawebp.png b/testdata/reallyawebp.png new file mode 100644 index 0000000..a608fc8 Binary files /dev/null and b/testdata/reallyawebp.png differ