Skip to content

Commit ccf5e49

Browse files
committed
Update References to handle slashes in reference values
1 parent 346761b commit ccf5e49

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lib/Github/Api/GitData/References.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public function tags($username, $repository)
2828

2929
public function show($username, $repository, $reference)
3030
{
31-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference));
31+
$reference = $this->encodeReference($reference);
32+
33+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference);
3234
}
3335

3436
public function create($username, $repository, array $params)
@@ -46,11 +48,20 @@ public function update($username, $repository, $reference, array $params)
4648
throw new MissingArgumentException('sha');
4749
}
4850

49-
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference), $params);
51+
$reference = $this->encodeReference($reference);
52+
53+
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference, $params);
5054
}
5155

5256
public function remove($username, $repository, $reference)
5357
{
54-
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.rawurlencode($reference));
58+
$reference = $this->encodeReference($reference);
59+
60+
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/refs/'.$reference);
61+
}
62+
63+
private function encodeReference($rawReference)
64+
{
65+
return implode('/', array_map('rawurlencode', explode('/', $rawReference)));
5566
}
5667
}

test/Github/Tests/Api/GitData/ReferencesTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@
22

33
namespace Github\Tests\Api;
44

5-
use Github\Tests\Api\TestCase;
6-
75
class ReferencesTest extends TestCase
86
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldNotEscapeSlashesInReferences()
11+
{
12+
$expectedValue = array('reference' => 'some data');
13+
14+
$api = $this->getApiMock();
15+
$api->expects($this->once())
16+
->method('get')
17+
->with('repos/l3l0/l3l0repo/git/refs/master/some%2A%26%40%23branch/dasd1212')
18+
->will($this->returnValue($expectedValue));
19+
20+
$this->assertEquals($expectedValue, $api->show('l3l0', 'l3l0repo', 'master/some*&@#branch/dasd1212'));
21+
}
22+
923
/**
1024
* @test
1125
*/

0 commit comments

Comments
 (0)