Skip to content

Commit 59ff8e1

Browse files
authored
fix(lib-storage): fix Location field decoding in Upload class (#5668)
1 parent 62c2ec4 commit 59ff8e1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/lib-storage/src/Upload.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,22 @@ describe(Upload.name, () => {
296296
expect(result.Location).toEqual("https://s3.region.amazonaws.com/example-bucket/example-key");
297297
});
298298

299+
it("should return a Location field with decoded slash symbols", async () => {
300+
const partSize = 1024 * 1024 * 5;
301+
const largeBuffer = Buffer.from("#".repeat(partSize + 10));
302+
const actionParams = { ...params, Body: largeBuffer };
303+
const completeMultipartMockWithLocation = completeMultipartMock.mockResolvedValueOnce({
304+
Location: "https://example-bucket.example-host.com/folder%2Fexample-key",
305+
});
306+
const upload = new Upload({
307+
params: actionParams,
308+
client: new S3({}),
309+
});
310+
const result = (await upload.done()) as CompleteMultipartUploadCommandOutput;
311+
expect(completeMultipartMockWithLocation).toHaveBeenCalledTimes(1);
312+
expect(result.Location).toEqual("https://example-bucket.example-host.com/folder/example-key");
313+
});
314+
299315
it("should upload using multi-part when parts are larger than part size", async () => {
300316
// create a string that's larger than 5MB.
301317
const partSize = 1024 * 1024 * 5;

lib/lib-storage/src/Upload.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ export class Upload extends EventEmitter {
334334
},
335335
};
336336
result = await this.client.send(new CompleteMultipartUploadCommand(uploadCompleteParams));
337+
if (typeof result?.Location === "string" && result.Location.includes("%2F")) {
338+
result.Location = result.Location.replace(/%2F/g, "/");
339+
}
337340
} else {
338341
result = this.singleUploadResult!;
339342
}

0 commit comments

Comments
 (0)