Skip to content

Commit 2b320f7

Browse files
author
Matt Humphrey
committed
Handle dots and slashes when encoding. Fixes #86 #87
1 parent f64c774 commit 2b320f7

11 files changed

+80
-64
lines changed

lib/Gitlab/Api/AbstractApi.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ protected function delete($path, array $parameters = array(), $requestHeaders =
111111
*/
112112
protected function getProjectPath($id, $path)
113113
{
114-
return 'projects/'.rawurlencode($id).'/'.$path;
114+
return 'projects/'.$this->encodePath($id).'/'.$path;
115+
}
116+
117+
/**
118+
* @param string $path
119+
* @return string
120+
*/
121+
protected function encodePath($path)
122+
{
123+
$path = rawurlencode($path);
124+
125+
return str_replace(array('%2F', '.'), array('/', '%2E'), $path);
115126
}
116127
}

lib/Gitlab/Api/Groups.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function all($page = 1, $per_page = self::PER_PAGE)
2323
*/
2424
public function search($query, $page = 1, $per_page = self::PER_PAGE)
2525
{
26-
return $this->get('groups?search='.rawurlencode($query), array(
26+
return $this->get('groups?search='.$this->encodePath($query), array(
2727
'page' => $page,
2828
'per_page' => $per_page
2929
));
@@ -35,7 +35,7 @@ public function search($query, $page = 1, $per_page = self::PER_PAGE)
3535
*/
3636
public function show($id)
3737
{
38-
return $this->get('groups/'.rawurlencode($id));
38+
return $this->get('groups/'.$this->encodePath($id));
3939
}
4040

4141
/**
@@ -59,7 +59,7 @@ public function create($name, $path, $description = null)
5959
*/
6060
public function remove($group_id)
6161
{
62-
return $this->delete('groups/'.rawurlencode($group_id));
62+
return $this->delete('groups/'.$this->encodePath($group_id));
6363
}
6464

6565
/**
@@ -69,7 +69,7 @@ public function remove($group_id)
6969
*/
7070
public function transfer($group_id, $project_id)
7171
{
72-
return $this->post('groups/'.rawurlencode($group_id).'/projects/'.rawurlencode($project_id));
72+
return $this->post('groups/'.$this->encodePath($group_id).'/projects/'.$this->encodePath($project_id));
7373
}
7474

7575
/**
@@ -80,7 +80,7 @@ public function transfer($group_id, $project_id)
8080
*/
8181
public function members($id, $page = 1, $per_page = self::PER_PAGE)
8282
{
83-
return $this->get('groups/'.rawurlencode($id).'/members', array(
83+
return $this->get('groups/'.$this->encodePath($id).'/members', array(
8484
'page' => $page,
8585
'per_page' => $per_page
8686
));
@@ -94,7 +94,7 @@ public function members($id, $page = 1, $per_page = self::PER_PAGE)
9494
*/
9595
public function addMember($group_id, $user_id, $access_level)
9696
{
97-
return $this->post('groups/'.rawurlencode($group_id).'/members', array(
97+
return $this->post('groups/'.$this->encodePath($group_id).'/members', array(
9898
'user_id' => $user_id,
9999
'access_level' => $access_level
100100
));
@@ -108,7 +108,7 @@ public function addMember($group_id, $user_id, $access_level)
108108
*/
109109
public function saveMember($group_id, $user_id, $access_level)
110110
{
111-
return $this->put('groups/'.rawurlencode($group_id).'/members/'.rawurlencode($user_id), array(
111+
return $this->put('groups/'.$this->encodePath($group_id).'/members/'.$this->encodePath($user_id), array(
112112
'access_level' => $access_level
113113
));
114114
}
@@ -120,6 +120,6 @@ public function saveMember($group_id, $user_id, $access_level)
120120
*/
121121
public function removeMember($group_id, $user_id)
122122
{
123-
return $this->delete('groups/'.rawurlencode($group_id).'/members/'.rawurlencode($user_id));
123+
return $this->delete('groups/'.$this->encodePath($group_id).'/members/'.$this->encodePath($user_id));
124124
}
125125
}

lib/Gitlab/Api/Issues.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function all($project_id = null, $page = 1, $per_page = self::PER_PAGE, a
2929
*/
3030
public function show($project_id, $issue_id)
3131
{
32-
return $this->get($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id)));
32+
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)));
3333
}
3434

3535
/**
@@ -50,7 +50,7 @@ public function create($project_id, array $params)
5050
*/
5151
public function update($project_id, $issue_id, array $params)
5252
{
53-
return $this->put($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id)), $params);
53+
return $this->put($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)), $params);
5454
}
5555

5656
/**
@@ -60,7 +60,7 @@ public function update($project_id, $issue_id, array $params)
6060
*/
6161
public function showComments($project_id, $issue_id)
6262
{
63-
return $this->get($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id)).'/notes');
63+
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes');
6464
}
6565

6666
/**
@@ -71,7 +71,7 @@ public function showComments($project_id, $issue_id)
7171
*/
7272
public function showComment($project_id, $issue_id, $note_id)
7373
{
74-
return $this->get($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id)).'/notes/'.rawurlencode($note_id));
74+
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes/'.$this->encodePath($note_id));
7575
}
7676

7777
/**
@@ -89,7 +89,7 @@ public function addComment($project_id, $issue_id, $body)
8989
$params = array('body' => $body);
9090
}
9191

92-
return $this->post($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id).'/notes'), $params);
92+
return $this->post($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/notes'), $params);
9393
}
9494

9595
/**
@@ -101,7 +101,7 @@ public function addComment($project_id, $issue_id, $body)
101101
*/
102102
public function updateComment($project_id, $issue_id, $note_id, $body)
103103
{
104-
return $this->put($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id).'/notes/'.rawurlencode($note_id)), array(
104+
return $this->put($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/notes/'.$this->encodePath($note_id)), array(
105105
'body' => $body
106106
));
107107
}

lib/Gitlab/Api/MergeRequests.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function closed($project_id, $page = 1, $per_page = self::PER_PAGE, $orde
8989
*/
9090
public function show($project_id, $mr_id)
9191
{
92-
return $this->get($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id)));
92+
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id)));
9393
}
9494

9595
/**
@@ -122,7 +122,7 @@ public function create($project_id, $source, $target, $title, $assignee = null,
122122
*/
123123
public function update($project_id, $mr_id, array $params)
124124
{
125-
return $this->put($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id)), $params);
125+
return $this->put($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id)), $params);
126126
}
127127

128128
/**
@@ -139,7 +139,7 @@ public function merge($project_id, $mr_id, $message = null)
139139
$params = array('merge_commit_message' => $message);
140140
}
141141

142-
return $this->put($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id).'/merge'), $params);
142+
return $this->put($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/merge'), $params);
143143
}
144144

145145
/**
@@ -149,7 +149,7 @@ public function merge($project_id, $mr_id, $message = null)
149149
*/
150150
public function showComments($project_id, $mr_id)
151151
{
152-
return $this->get($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id).'/comments'));
152+
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/comments'));
153153
}
154154

155155
/**
@@ -160,7 +160,7 @@ public function showComments($project_id, $mr_id)
160160
*/
161161
public function addComment($project_id, $mr_id, $note)
162162
{
163-
return $this->post($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id).'/comments'), array(
163+
return $this->post($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/comments'), array(
164164
'note' => $note
165165
));
166166
}
@@ -172,6 +172,6 @@ public function addComment($project_id, $mr_id, $note)
172172
*/
173173
public function changes($project_id, $mr_id)
174174
{
175-
return $this->get($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id).'/changes'));
175+
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/changes'));
176176
}
177177
}

lib/Gitlab/Api/Milestones.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
2323
*/
2424
public function show($project_id, $milestone_id)
2525
{
26-
return $this->get($this->getProjectPath($project_id, 'milestones/'.rawurlencode($milestone_id)));
26+
return $this->get($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id)));
2727
}
2828

2929
/**
@@ -44,7 +44,7 @@ public function create($project_id, array $params)
4444
*/
4545
public function update($project_id, $milestone_id, array $params)
4646
{
47-
return $this->put($this->getProjectPath($project_id, 'milestones/'.rawurlencode($milestone_id)), $params);
47+
return $this->put($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id)), $params);
4848
}
4949

5050
/**
@@ -54,6 +54,6 @@ public function update($project_id, $milestone_id, array $params)
5454
*/
5555
public function issues($project_id, $milestone_id)
5656
{
57-
return $this->get($this->getProjectPath($project_id, 'milestones/'.rawurlencode($milestone_id).'/issues'));
57+
return $this->get($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id).'/issues'));
5858
}
5959
}

lib/Gitlab/Api/Projects.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function owned($page = 1, $per_page = self::PER_PAGE, $order_by = self::O
6666
*/
6767
public function search($query, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
6868
{
69-
return $this->get('projects/search/'.rawurlencode($query), array(
69+
return $this->get('projects/search/'.$this->encodePath($query), array(
7070
'page' => $page,
7171
'per_page' => $per_page,
7272
'order_by' => $order_by,
@@ -80,7 +80,7 @@ public function search($query, $page = 1, $per_page = self::PER_PAGE, $order_by
8080
*/
8181
public function show($project_id)
8282
{
83-
return $this->get('projects/'.rawurlencode($project_id));
83+
return $this->get('projects/'.$this->encodePath($project_id));
8484
}
8585

8686
/**
@@ -105,7 +105,7 @@ public function createForUser($user_id, $name, array $params = array())
105105
{
106106
$params['name'] = $name;
107107

108-
return $this->post('projects/user/'.rawurlencode($user_id), $params);
108+
return $this->post('projects/user/'.$this->encodePath($user_id), $params);
109109
}
110110

111111
/**
@@ -115,7 +115,7 @@ public function createForUser($user_id, $name, array $params = array())
115115
*/
116116
public function update($project_id, array $params)
117117
{
118-
return $this->put('projects/'.rawurlencode($project_id), $params);
118+
return $this->put('projects/'.$this->encodePath($project_id), $params);
119119
}
120120

121121
/**
@@ -124,7 +124,7 @@ public function update($project_id, array $params)
124124
*/
125125
public function remove($project_id)
126126
{
127-
return $this->delete('projects/'.rawurlencode($project_id));
127+
return $this->delete('projects/'.$this->encodePath($project_id));
128128
}
129129

130130
/**
@@ -146,7 +146,7 @@ public function members($project_id, $username_query = null)
146146
*/
147147
public function member($project_id, $user_id)
148148
{
149-
return $this->get($this->getProjectPath($project_id, 'members/'.rawurlencode($user_id)));
149+
return $this->get($this->getProjectPath($project_id, 'members/'.$this->encodePath($user_id)));
150150
}
151151

152152
/**
@@ -207,7 +207,7 @@ public function hooks($project_id, $page = 1, $per_page = self::PER_PAGE)
207207
*/
208208
public function hook($project_id, $hook_id)
209209
{
210-
return $this->get($this->getProjectPath($project_id, 'hooks/'.rawurlencode($hook_id)));
210+
return $this->get($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)));
211211
}
212212

213213
/**
@@ -235,7 +235,7 @@ public function addHook($project_id, $url, array $params = array())
235235
*/
236236
public function updateHook($project_id, $hook_id, array $params)
237237
{
238-
return $this->put($this->getProjectPath($project_id, 'hooks/'.rawurlencode($hook_id)), $params);
238+
return $this->put($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)), $params);
239239
}
240240

241241
/**
@@ -245,7 +245,7 @@ public function updateHook($project_id, $hook_id, array $params)
245245
*/
246246
public function removeHook($project_id, $hook_id)
247247
{
248-
return $this->delete($this->getProjectPath($project_id, 'hooks/'.rawurlencode($hook_id)));
248+
return $this->delete($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)));
249249
}
250250

251251
/**
@@ -264,7 +264,7 @@ public function keys($project_id)
264264
*/
265265
public function key($project_id, $key_id)
266266
{
267-
return $this->get($this->getProjectPath($project_id, 'keys/'.rawurlencode($key_id)));
267+
return $this->get($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id)));
268268
}
269269

270270
/**
@@ -288,7 +288,7 @@ public function addKey($project_id, $title, $key)
288288
*/
289289
public function removeKey($project_id, $key_id)
290290
{
291-
return $this->delete($this->getProjectPath($project_id, 'keys/'.rawurlencode($key_id)));
291+
return $this->delete($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id)));
292292
}
293293

294294
/**
@@ -353,7 +353,7 @@ public function removeLabel($project_id, $name)
353353
*/
354354
public function createForkRelation($project_id, $forked_project_id)
355355
{
356-
return $this->post($this->getProjectPath($project_id, 'fork/'.rawurlencode($forked_project_id)));
356+
return $this->post($this->getProjectPath($project_id, 'fork/'.$this->encodePath($forked_project_id)));
357357
}
358358

359359
/**
@@ -373,7 +373,7 @@ public function removeForkRelation($project_id)
373373
*/
374374
public function setService($project_id, $service_name, array $params = array())
375375
{
376-
return $this->put($this->getProjectPath($project_id, 'services/'.rawurlencode($service_name)), $params);
376+
return $this->put($this->getProjectPath($project_id, 'services/'.$this->encodePath($service_name)), $params);
377377
}
378378

379379
/**
@@ -383,6 +383,6 @@ public function setService($project_id, $service_name, array $params = array())
383383
*/
384384
public function removeService($project_id, $service_name)
385385
{
386-
return $this->delete($this->getProjectPath($project_id, 'services/'.rawurlencode($service_name)));
386+
return $this->delete($this->getProjectPath($project_id, 'services/'.$this->encodePath($service_name)));
387387
}
388388
}

0 commit comments

Comments
 (0)