Skip to content

Commit

Permalink
feat: decoded encoded URLs (#2935)
Browse files Browse the repository at this point in the history
  • Loading branch information
yenfryherrerafeliz authored Jun 25, 2024
1 parent cec444c commit bbf5be8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changes/nextrelease/feat-urldecode-location.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "feature",
"category": "",
"description": "Decodes URL returned by CompleteMultipartUpload operation so special characters are removed."
}
]
2 changes: 1 addition & 1 deletion src/S3/PutObjectUrlMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function (ResultInterface $result) use ($command) {
: null;
break;
case 'CompleteMultipartUpload':
$result['ObjectURL'] = $result['Location'];
$result['ObjectURL'] = urldecode($result['Location'] ?? '');
break;
}
return $result;
Expand Down
4 changes: 2 additions & 2 deletions tests/S3/ObjectCopierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ public function testS3ObjectCopierDoesTransformUnicodeKeyToEncodedURL()

public function MultipartCopierProvider(){
return [
["中文", "%E4%B8%AD%E6%96%87"],
["文件夹/文件", "%E6%96%87%E4%BB%B6%E5%A4%B9/%E6%96%87%E4%BB%B6"],
["中文", "文件夹/文件"],
["文件夹/文件", "中文"],
["first-folder/second-folder/key", "first-folder/second-folder/key"],
];
}
Expand Down
23 changes: 23 additions & 0 deletions tests/S3/PutObjectUrlMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,27 @@ public function testAddsObjectUrlToCompleteMultipart()
$result['ObjectURL']
);
}

public function testDecodesEncodedUrl()
{
$client = $this->getTestClient('s3');
$this->addMockResults($client, [
[
'Location' => 'https://test.s3.amazonaws.com/testdir%2Ftestfile',
'@metadata' => [
'effectiveUri' => 'http://foo.com',
]
]
]);
$result = $client->completeMultipartUpload([
'Bucket' => 'test',
'Key' => 'key',
'UploadId' => '123'
]);

$this->assertSame(
'https://test.s3.amazonaws.com/testdir/testfile',
$result['ObjectURL']
);
}
}

0 comments on commit bbf5be8

Please sign in to comment.