Skip to content

Commit

Permalink
Merge pull request #205 from outlawtorn/master
Browse files Browse the repository at this point in the history
Add icon and webp to secondGuessSourceContentType check
  • Loading branch information
papandreou authored Jun 2, 2024
2 parents a41e38b + e7f7401 commit 278db02
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/processImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Binary file added reallyaico.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added reallyawebp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions test/processImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,27 @@ describe('express-processimage', () => {
beforeEach(() => {
config.secondGuessSourceContentType = true;
});
it('should recover gracefully when attempting to process a wrongly named webp', () => {

Check failure on line 1389 in test/processImage.js

View workflow job for this annotation

GitHub Actions / Lint

Expected line break before this statement
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', () => {

Check failure on line 1401 in test/processImage.js

View workflow job for this annotation

GitHub Actions / Lint

Expected line break before this statement
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', () => {

Check failure on line 1410 in test/processImage.js

View workflow job for this annotation

GitHub Actions / Lint

Expected line break before this statement
config.debug = true;
return expect('GET /reallyajpeg.gif?resize=40,35', 'to yield response', {
Expand Down
Binary file added testdata/reallyaico.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testdata/reallyawebp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 278db02

Please sign in to comment.