diff --git a/source/image-handler/image-request.ts b/source/image-handler/image-request.ts index ad4fae161..1329b8ded 100644 --- a/source/image-handler/image-request.ts +++ b/source/image-handler/image-request.ts @@ -453,6 +453,7 @@ export class ImageRequest { case "FFD8FFED": case "FFD8FFEE": case "FFD8FFE1": + case "FFD8FFE2": return ContentTypes.JPEG; case "52494646": return ContentTypes.WEBP; diff --git a/source/image-handler/test/image-request/infer-image-type.spec.ts b/source/image-handler/test/image-request/infer-image-type.spec.ts index 301a746bf..abb2057e7 100644 --- a/source/image-handler/test/image-request/infer-image-type.spec.ts +++ b/source/image-handler/test/image-request/infer-image-type.spec.ts @@ -12,21 +12,16 @@ describe("inferImageType", () => { const secretsManager = new SecretsManager(); const secretProvider = new SecretProvider(secretsManager); - it('Should pass if it returns "image/jpeg"', () => { - // Arrange - const imageBuffer = Buffer.from([0xff, 0xd8, 0xff, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); - - // Act - const imageRequest = new ImageRequest(s3Client, secretProvider); - const result = imageRequest.inferImageType(imageBuffer); - - // Assert - expect(result).toEqual("image/jpeg"); - }); - - it('Should pass if it returns "image/jpeg for a magic number of FFD8FFED"', () => { - // Arrange - const imageBuffer = Buffer.from([0xff, 0xd8, 0xff, 0xed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); + test.each([ + { value: "FFD8FFDB" }, + { value: "FFD8FFE0" }, + { value: "FFD8FFED" }, + { value: "FFD8FFEE" }, + { value: "FFD8FFE1" }, + { value: "FFD8FFE2" }, + ])('Should pass if it returns "image/jpeg" for a magic number of $value', ({ value }) => { + const byteValues = value.match(/.{1,2}/g).map((x) => parseInt(x, 16)); + const imageBuffer = Buffer.from(byteValues.concat(new Array(8).fill(0x00))); // Act const imageRequest = new ImageRequest(s3Client, secretProvider);