Skip to content

Commit 01e5503

Browse files
committed
[Bug] Include format param only in API v1
Using 'format' parameter in API v2 will result in a 500 error. closes #64
1 parent 39f0ec9 commit 01e5503

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/Bitbucket/API/Http/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ protected function createRequest($method, $url)
268268
}
269269

270270
// change the response format
271-
if (strpos($url, 'format=') === false) {
271+
if ($this->getApiVersion() === '1.0' && strpos($url, 'format=') === false) {
272272
$url .= (strpos($url, '?') === false ? '?' : '&').'format='.$this->getResponseFormat();
273273
}
274274

test/Bitbucket/Tests/API/Http/ClientTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,33 @@ public function testCurrentApiVersion()
207207
$this->assertTrue($client->isApiVersion('2'));
208208
}
209209

210+
/**
211+
* @ticket 64
212+
*/
213+
public function testIncludeFormatParamOnlyInV1()
214+
{
215+
$endpoint = sprintf(
216+
'repositories/gentlero/bitbucket-api/src/%s/%s',
217+
'develop',
218+
'lib/Bitbucket/API/Repositories'
219+
);
220+
$params = $headers = [];
221+
222+
$baseClient = $this->getBrowserMock();
223+
$client = new Client(['api_version' => '2.0'], $baseClient);
224+
$client->get($endpoint, $params, $headers);
225+
226+
/** @noinspection PhpUndefinedMethodInspection */
227+
$req = $client->getLastRequest()->getResource();
228+
$parts = parse_url($req);
229+
230+
if (false === array_key_exists('query', $parts)) {
231+
$parts['query'] = '';
232+
}
233+
234+
$this->assertFalse(strpos($parts['query'], 'format'));
235+
}
236+
210237
private function getListenerMock($name = 'dummy')
211238
{
212239
$listener = $this->getMock('Bitbucket\API\Http\Listener\ListenerInterface');

0 commit comments

Comments
 (0)