Skip to content

Commit 2c92cc5

Browse files
authored
strip quotes in storage emulator header boundary (#4825)
1 parent d446fff commit 2c92cc5

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Replaces underlying terminal coloring library.
2+
- Make storage emulator multipart parsing handle quotes in boundary header #3953
23
- Make storage emulator content type case insensitive #3953

src/emulator/storage/multipart.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ function splitBufferByDelimiter(buffer: Buffer, delimiter: string, maxResults =
5151
* @param body multipart request body as a Buffer
5252
*/
5353
function parseMultipartRequestBody(boundaryId: string, body: Buffer): MultipartRequestBody {
54-
const boundaryString = `--${boundaryId}`;
54+
// strip additional surrounding single and double quotes, cloud sdks have additional quote here
55+
const cleanBoundaryId = boundaryId.replace(/^["'](.+(?=["']$))["']$/, "$1");
56+
const boundaryString = `--${cleanBoundaryId}`;
5557
const bodyParts = splitBufferByDelimiter(body, boundaryString).map((buf) => {
5658
// Remove the \r\n and the beginning of each part left from the boundary line.
5759
return Buffer.from(buf.slice(2));

src/test/emulators/storage/multipart.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ hello there!
7878
);
7979
});
8080

81+
it("parses an upload object multipart request with additional quotes in the boundary value", () => {
82+
const contentTypeHeaderWithDoubleQuotes = `multipart/related; boundary="b1d5b2e3-1845-4338-9400-6ac07ce53c1e"`;
83+
84+
let { metadataRaw, dataRaw } = parseObjectUploadMultipartRequest(
85+
contentTypeHeaderWithDoubleQuotes,
86+
BODY
87+
);
88+
89+
expect(metadataRaw).to.equal('{"contentType":"text/plain"}');
90+
expect(dataRaw.toString()).to.equal("hello there!\n");
91+
92+
const contentTypeHeaderWithSingleQuotes = `multipart/related; boundary='b1d5b2e3-1845-4338-9400-6ac07ce53c1e'`;
93+
94+
({ metadataRaw, dataRaw } = parseObjectUploadMultipartRequest(
95+
contentTypeHeaderWithSingleQuotes,
96+
BODY
97+
));
98+
99+
expect(metadataRaw).to.equal('{"contentType":"text/plain"}');
100+
expect(dataRaw.toString()).to.equal("hello there!\n");
101+
});
102+
81103
it("fails to parse when body has wrong number of parts", () => {
82104
const invalidBody = Buffer.from(`--b1d5b2e3-1845-4338-9400-6ac07ce53c1e\r
83105
Content-Type: application/json\r

0 commit comments

Comments
 (0)