Skip to content

Commit a6c911e

Browse files
authored
Merge pull request #401 from qiniu:fix/entry-encode
fix entry encode not work with empty key string and add test cases
2 parents 4bbddbd + ad382d9 commit a6c911e

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## Next Version
4+
* 对象存储,修复无法对 key 为空字符串的对象进行操作
5+
36
## 7.8.0 (2022-10-25)
47
* 移除不推荐域名,并增加区域亚太-首尔和华东-浙江2
58
* 对象存储,修复断点上传的文件内容不正确

src/Qiniu/functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ function json_decode($json, $assoc = false, $depth = 512)
129129
* @param string $key 待操作的文件名
130130
*
131131
* @return string 符合七牛API规格的数据格式
132-
* @link http://developer.qiniu.com/docs/v6/api/reference/data-formats.html
132+
* @link https://developer.qiniu.com/kodo/api/data-format
133133
*/
134-
function entry($bucket, $key)
134+
function entry($bucket, $key = null)
135135
{
136136
$en = $bucket;
137-
if (!empty($key)) {
137+
if ($key !== null) {
138138
$en = $bucket . ':' . $key;
139139
}
140140
return base64_urlSafeEncode($en);

tests/Qiniu/Tests/EntryTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
namespace Qiniu\Tests;
3+
4+
use Qiniu;
5+
6+
class EntryTest extends \PHPUnit_Framework_TestCase
7+
{
8+
public function testNormal()
9+
{
10+
$bucket = 'qiniuphotos';
11+
$key = 'gogopher.jpg';
12+
$encodeEntryURI = Qiniu\entry($bucket, $key);
13+
$this->assertEquals('cWluaXVwaG90b3M6Z29nb3BoZXIuanBn', $encodeEntryURI);
14+
}
15+
16+
public function testKeyEmpty()
17+
{
18+
$bucket = 'qiniuphotos';
19+
$key = '';
20+
$encodeEntryURI = Qiniu\entry($bucket, $key);
21+
$this->assertEquals('cWluaXVwaG90b3M6', $encodeEntryURI);
22+
}
23+
24+
public function testKeyNull()
25+
{
26+
$bucket = 'qiniuphotos';
27+
$key = null;
28+
$encodeEntryURI = Qiniu\entry($bucket, $key);
29+
$this->assertEquals('cWluaXVwaG90b3M=', $encodeEntryURI);
30+
}
31+
32+
public function testKeyNeedReplacePlusSymbol()
33+
{
34+
$bucket = 'qiniuphotos';
35+
$key = '012ts>a';
36+
$encodeEntryURI = Qiniu\entry($bucket, $key);
37+
$this->assertEquals('cWluaXVwaG90b3M6MDEydHM-YQ==', $encodeEntryURI);
38+
}
39+
40+
public function testKeyNeedReplaceSlashSymbol()
41+
{
42+
$bucket = 'qiniuphotos';
43+
$key = '012ts?a';
44+
$encodeEntryURI = Qiniu\entry($bucket, $key);
45+
$this->assertEquals('cWluaXVwaG90b3M6MDEydHM_YQ==', $encodeEntryURI);
46+
}
47+
}

0 commit comments

Comments
 (0)