From e9603754b7f698e27ddfae0b9ee74744cc98f535 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 3 Aug 2022 13:38:20 -0400 Subject: [PATCH 1/2] make storage emulator content type case insensitive --- src/emulator/storage/multipart.ts | 4 ++-- src/test/emulators/storage/multipart.spec.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/emulator/storage/multipart.ts b/src/emulator/storage/multipart.ts index 54a68fc57e5..955f62b57fb 100644 --- a/src/emulator/storage/multipart.ts +++ b/src/emulator/storage/multipart.ts @@ -91,8 +91,8 @@ function parseMultipartRequestBodyPart(bodyPart: Buffer): MultipartRequestBodyPa // splitting the entire body part buffer. const sections = splitBufferByDelimiter(bodyPart, LINE_SEPARATOR, /* maxResults = */ 3); - const contentTypeRaw = sections[0].toString(); - if (!contentTypeRaw.startsWith("Content-Type: ")) { + const contentTypeRaw = sections[0].toString().toLowerCase(); + if (!contentTypeRaw.startsWith("content-type: ")) { throw new Error(`Failed to parse multipart request body part. Missing content type.`); } diff --git a/src/test/emulators/storage/multipart.spec.ts b/src/test/emulators/storage/multipart.spec.ts index eb983e166db..44d3e96132c 100644 --- a/src/test/emulators/storage/multipart.spec.ts +++ b/src/test/emulators/storage/multipart.spec.ts @@ -45,6 +45,25 @@ Content-Type: text/plain\r expect(dataRaw.byteLength).to.equal(data.byteLength); }); + it("parses an upload object multipart request with lowercase content-type", () => { + const body = Buffer.from(`--b1d5b2e3-1845-4338-9400-6ac07ce53c1e\r +content-type: application/json\r +\r +{"contentType":"text/plain"}\r +--b1d5b2e3-1845-4338-9400-6ac07ce53c1e\r +content-type: text/plain\r +\r +hello there! +\r +--b1d5b2e3-1845-4338-9400-6ac07ce53c1e--\r +`); + + const { metadataRaw, dataRaw } = parseObjectUploadMultipartRequest(CONTENT_TYPE_HEADER, body); + + expect(metadataRaw).to.equal('{"contentType":"text/plain"}'); + expect(dataRaw.toString()).to.equal("hello there!\n"); + }); + it("fails to parse with invalid Content-Type value", () => { const invalidContentTypeHeader = "blah"; expect(() => parseObjectUploadMultipartRequest(invalidContentTypeHeader, BODY)).to.throw( From 018ddfb8af463b05115775cd847ccb42af8c777a Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 3 Aug 2022 13:39:42 -0400 Subject: [PATCH 2/2] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04b9fc455ae..a02a15bb986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ - Replaces underlying terminal coloring library. +- Make storage emulator content type case insensitive #3953