Skip to content

Commit 4648658

Browse files
committed
Repository::create() should throw exception when empty string is provided as
1 parent e0b6320 commit 4648658

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Bitbucket/API/Repositories/Repository.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public function create($account, $repo, $params = array())
7070

7171
// allow developer to directly specify params as json if (s)he wants.
7272
if ('string' === gettype($params)) {
73+
if (empty($params)) {
74+
throw new \InvalidArgumentException('Invalid JSON provided.');
75+
}
76+
7377
$params = json_decode($params, true);
7478

7579
if (JSON_ERROR_NONE !== json_last_error()) {

test/Bitbucket/Tests/API/Repositories/RepositoryTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ public function testCreateRepositoryWithDefaultParams()
9494
$repo->create('gentle', 'new-repo', array());
9595
}
9696

97+
/**
98+
* @ticket 26
99+
* @expectedException \InvalidArgumentException
100+
*/
101+
public function testCreateRepositoryWithWrongParamsType()
102+
{
103+
/** @var \Bitbucket\API\Repositories\Repository $repo */
104+
$repo = $this->getApiMock('Bitbucket\API\Repositories\Repository');
105+
106+
$repo->create('gentle', 'new-repo', '');
107+
}
108+
97109
public function testCreateRepositorySuccess()
98110
{
99111
$endpoint = 'repositories';

0 commit comments

Comments
 (0)