Skip to content

Commit 21f4524

Browse files
author
Matt Humphrey
committed
Only revert encoded slashes when dealing with branch names. Fixes #89
1 parent 2b320f7 commit 21f4524

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

lib/Gitlab/Api/AbstractApi.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ protected function encodePath($path)
122122
{
123123
$path = rawurlencode($path);
124124

125-
return str_replace(array('%2F', '.'), array('/', '%2E'), $path);
125+
return str_replace('.', '%2E', $path);
126126
}
127127
}

lib/Gitlab/Api/Repositories.php

+16-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function branches($project_id)
1818
*/
1919
public function branch($project_id, $branch_id)
2020
{
21-
return $this->get($this->getProjectPath($project_id, 'repository/branches/'.$this->encodePath($branch_id)));
21+
return $this->get($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_id)));
2222
}
2323

2424
/**
@@ -42,7 +42,7 @@ public function createBranch($project_id, $branch_name, $ref)
4242
*/
4343
public function deleteBranch($project_id, $branch_name)
4444
{
45-
return $this->delete($this->getProjectPath($project_id, 'repository/branches/'.$this->encodePath($branch_name)));
45+
return $this->delete($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_name)));
4646
}
4747

4848
/**
@@ -52,7 +52,7 @@ public function deleteBranch($project_id, $branch_name)
5252
*/
5353
public function protectBranch($project_id, $branch_name)
5454
{
55-
return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodePath($branch_name).'/protect'));
55+
return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_name).'/protect'));
5656
}
5757

5858
/**
@@ -62,7 +62,7 @@ public function protectBranch($project_id, $branch_name)
6262
*/
6363
public function unprotectBranch($project_id, $branch_name)
6464
{
65-
return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodePath($branch_name).'/unprotect'));
65+
return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_name).'/unprotect'));
6666
}
6767

6868
/**
@@ -155,7 +155,7 @@ public function compare($project_id, $fromShaOrMaster, $toShaOrMaster)
155155
{
156156
return $this->get($this->getProjectPath(
157157
$project_id,
158-
'repository/compare?from='.$this->encodePath($fromShaOrMaster).'&to='.$this->encodePath($toShaOrMaster)
158+
'repository/compare?from='.$this->encodeBranch($fromShaOrMaster).'&to='.$this->encodeBranch($toShaOrMaster)
159159
));
160160
}
161161

@@ -270,4 +270,15 @@ public function contributors($project_id)
270270
{
271271
return $this->get($this->getProjectPath($project_id, 'repository/contributors'));
272272
}
273+
274+
/**
275+
* @param string $path
276+
* @return string
277+
*/
278+
protected function encodeBranch($path)
279+
{
280+
$path = $this->encodePath($path);
281+
282+
return str_replace('%2F', '/', $path);
283+
}
273284
}

test/Gitlab/Tests/Api/ProjectsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function shouldSearchProjects()
8383
$api = $this->getMultipleProjectsRequestMock('projects/search/a%2Eproject', $expectedArray);
8484
$this->assertEquals($expectedArray, $api->search('a.project'));
8585

86-
$api = $this->getMultipleProjectsRequestMock('projects/search/a/project', $expectedArray);
86+
$api = $this->getMultipleProjectsRequestMock('projects/search/a%2Fproject', $expectedArray);
8787
$this->assertEquals($expectedArray, $api->search('a/project'));
8888
}
8989

0 commit comments

Comments
 (0)