Skip to content

Strip quotes in storage emulator header boundaryId #4825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Replaces underlying terminal coloring library.
- Make storage emulator multipart parsing handle quotes in boundary header #3953
- Make storage emulator content type case insensitive #3953
4 changes: 3 additions & 1 deletion src/emulator/storage/multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ function splitBufferByDelimiter(buffer: Buffer, delimiter: string, maxResults =
* @param body multipart request body as a Buffer
*/
function parseMultipartRequestBody(boundaryId: string, body: Buffer): MultipartRequestBody {
const boundaryString = `--${boundaryId}`;
// strip additional surrounding single and double quotes, cloud sdks have additional quote here
const cleanBoundaryId = boundaryId.replace(/^["'](.+(?=["']$))["']$/, "$1");
const boundaryString = `--${cleanBoundaryId}`;
const bodyParts = splitBufferByDelimiter(body, boundaryString).map((buf) => {
// Remove the \r\n and the beginning of each part left from the boundary line.
return Buffer.from(buf.slice(2));
Expand Down
22 changes: 22 additions & 0 deletions src/test/emulators/storage/multipart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ hello there!
);
});

it("parses an upload object multipart request with additional quotes in the boundary value", () => {
const contentTypeHeaderWithDoubleQuotes = `multipart/related; boundary="b1d5b2e3-1845-4338-9400-6ac07ce53c1e"`;

let { metadataRaw, dataRaw } = parseObjectUploadMultipartRequest(
contentTypeHeaderWithDoubleQuotes,
BODY
);

expect(metadataRaw).to.equal('{"contentType":"text/plain"}');
expect(dataRaw.toString()).to.equal("hello there!\n");

const contentTypeHeaderWithSingleQuotes = `multipart/related; boundary='b1d5b2e3-1845-4338-9400-6ac07ce53c1e'`;

({ metadataRaw, dataRaw } = parseObjectUploadMultipartRequest(
contentTypeHeaderWithSingleQuotes,
BODY
));

expect(metadataRaw).to.equal('{"contentType":"text/plain"}');
expect(dataRaw.toString()).to.equal("hello there!\n");
});

it("fails to parse when body has wrong number of parts", () => {
const invalidBody = Buffer.from(`--b1d5b2e3-1845-4338-9400-6ac07ce53c1e\r
Content-Type: application/json\r
Expand Down