diff --git a/CHANGELOG.md b/CHANGELOG.md index e1948c56..4deecdb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## Next Version +* 对象存储,修复无法对 key 为空字符串的对象进行操作 + ## 7.8.0 (2022-10-25) * 移除不推荐域名,并增加区域亚太-首尔和华东-浙江2 * 对象存储,修复断点上传的文件内容不正确 diff --git a/src/Qiniu/functions.php b/src/Qiniu/functions.php index 3c03455e..9a768e6f 100644 --- a/src/Qiniu/functions.php +++ b/src/Qiniu/functions.php @@ -129,12 +129,12 @@ function json_decode($json, $assoc = false, $depth = 512) * @param string $key 待操作的文件名 * * @return string 符合七牛API规格的数据格式 - * @link http://developer.qiniu.com/docs/v6/api/reference/data-formats.html + * @link https://developer.qiniu.com/kodo/api/data-format */ - function entry($bucket, $key) + function entry($bucket, $key = null) { $en = $bucket; - if (!empty($key)) { + if ($key !== null) { $en = $bucket . ':' . $key; } return base64_urlSafeEncode($en); diff --git a/tests/Qiniu/Tests/EntryTest.php b/tests/Qiniu/Tests/EntryTest.php new file mode 100644 index 00000000..455deea5 --- /dev/null +++ b/tests/Qiniu/Tests/EntryTest.php @@ -0,0 +1,47 @@ +assertEquals('cWluaXVwaG90b3M6Z29nb3BoZXIuanBn', $encodeEntryURI); + } + + public function testKeyEmpty() + { + $bucket = 'qiniuphotos'; + $key = ''; + $encodeEntryURI = Qiniu\entry($bucket, $key); + $this->assertEquals('cWluaXVwaG90b3M6', $encodeEntryURI); + } + + public function testKeyNull() + { + $bucket = 'qiniuphotos'; + $key = null; + $encodeEntryURI = Qiniu\entry($bucket, $key); + $this->assertEquals('cWluaXVwaG90b3M=', $encodeEntryURI); + } + + public function testKeyNeedReplacePlusSymbol() + { + $bucket = 'qiniuphotos'; + $key = '012ts>a'; + $encodeEntryURI = Qiniu\entry($bucket, $key); + $this->assertEquals('cWluaXVwaG90b3M6MDEydHM-YQ==', $encodeEntryURI); + } + + public function testKeyNeedReplaceSlashSymbol() + { + $bucket = 'qiniuphotos'; + $key = '012ts?a'; + $encodeEntryURI = Qiniu\entry($bucket, $key); + $this->assertEquals('cWluaXVwaG90b3M6MDEydHM_YQ==', $encodeEntryURI); + } +}