Skip to content

Commit

Permalink
Handle dots and slashes when encoding. Fixes #86 #87
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Humphrey committed May 6, 2015
1 parent f64c774 commit 2b320f7
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 64 deletions.
13 changes: 12 additions & 1 deletion lib/Gitlab/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ protected function delete($path, array $parameters = array(), $requestHeaders =
*/
protected function getProjectPath($id, $path)
{
return 'projects/'.rawurlencode($id).'/'.$path;
return 'projects/'.$this->encodePath($id).'/'.$path;
}

/**
* @param string $path
* @return string
*/
protected function encodePath($path)
{
$path = rawurlencode($path);

return str_replace(array('%2F', '.'), array('/', '%2E'), $path);
}
}
16 changes: 8 additions & 8 deletions lib/Gitlab/Api/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function all($page = 1, $per_page = self::PER_PAGE)
*/
public function search($query, $page = 1, $per_page = self::PER_PAGE)
{
return $this->get('groups?search='.rawurlencode($query), array(
return $this->get('groups?search='.$this->encodePath($query), array(
'page' => $page,
'per_page' => $per_page
));
Expand All @@ -35,7 +35,7 @@ public function search($query, $page = 1, $per_page = self::PER_PAGE)
*/
public function show($id)
{
return $this->get('groups/'.rawurlencode($id));
return $this->get('groups/'.$this->encodePath($id));
}

/**
Expand All @@ -59,7 +59,7 @@ public function create($name, $path, $description = null)
*/
public function remove($group_id)
{
return $this->delete('groups/'.rawurlencode($group_id));
return $this->delete('groups/'.$this->encodePath($group_id));
}

/**
Expand All @@ -69,7 +69,7 @@ public function remove($group_id)
*/
public function transfer($group_id, $project_id)
{
return $this->post('groups/'.rawurlencode($group_id).'/projects/'.rawurlencode($project_id));
return $this->post('groups/'.$this->encodePath($group_id).'/projects/'.$this->encodePath($project_id));
}

/**
Expand All @@ -80,7 +80,7 @@ public function transfer($group_id, $project_id)
*/
public function members($id, $page = 1, $per_page = self::PER_PAGE)
{
return $this->get('groups/'.rawurlencode($id).'/members', array(
return $this->get('groups/'.$this->encodePath($id).'/members', array(
'page' => $page,
'per_page' => $per_page
));
Expand All @@ -94,7 +94,7 @@ public function members($id, $page = 1, $per_page = self::PER_PAGE)
*/
public function addMember($group_id, $user_id, $access_level)
{
return $this->post('groups/'.rawurlencode($group_id).'/members', array(
return $this->post('groups/'.$this->encodePath($group_id).'/members', array(
'user_id' => $user_id,
'access_level' => $access_level
));
Expand All @@ -108,7 +108,7 @@ public function addMember($group_id, $user_id, $access_level)
*/
public function saveMember($group_id, $user_id, $access_level)
{
return $this->put('groups/'.rawurlencode($group_id).'/members/'.rawurlencode($user_id), array(
return $this->put('groups/'.$this->encodePath($group_id).'/members/'.$this->encodePath($user_id), array(
'access_level' => $access_level
));
}
Expand All @@ -120,6 +120,6 @@ public function saveMember($group_id, $user_id, $access_level)
*/
public function removeMember($group_id, $user_id)
{
return $this->delete('groups/'.rawurlencode($group_id).'/members/'.rawurlencode($user_id));
return $this->delete('groups/'.$this->encodePath($group_id).'/members/'.$this->encodePath($user_id));
}
}
12 changes: 6 additions & 6 deletions lib/Gitlab/Api/Issues.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function all($project_id = null, $page = 1, $per_page = self::PER_PAGE, a
*/
public function show($project_id, $issue_id)
{
return $this->get($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id)));
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)));
}

/**
Expand All @@ -50,7 +50,7 @@ public function create($project_id, array $params)
*/
public function update($project_id, $issue_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id)), $params);
return $this->put($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)), $params);
}

/**
Expand All @@ -60,7 +60,7 @@ public function update($project_id, $issue_id, array $params)
*/
public function showComments($project_id, $issue_id)
{
return $this->get($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id)).'/notes');
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes');
}

/**
Expand All @@ -71,7 +71,7 @@ public function showComments($project_id, $issue_id)
*/
public function showComment($project_id, $issue_id, $note_id)
{
return $this->get($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id)).'/notes/'.rawurlencode($note_id));
return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes/'.$this->encodePath($note_id));
}

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

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

/**
Expand All @@ -101,7 +101,7 @@ public function addComment($project_id, $issue_id, $body)
*/
public function updateComment($project_id, $issue_id, $note_id, $body)
{
return $this->put($this->getProjectPath($project_id, 'issues/'.rawurlencode($issue_id).'/notes/'.rawurlencode($note_id)), array(
return $this->put($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/notes/'.$this->encodePath($note_id)), array(
'body' => $body
));
}
Expand Down
12 changes: 6 additions & 6 deletions lib/Gitlab/Api/MergeRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function closed($project_id, $page = 1, $per_page = self::PER_PAGE, $orde
*/
public function show($project_id, $mr_id)
{
return $this->get($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id)));
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id)));
}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ public function create($project_id, $source, $target, $title, $assignee = null,
*/
public function update($project_id, $mr_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id)), $params);
return $this->put($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id)), $params);
}

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

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

/**
Expand All @@ -149,7 +149,7 @@ public function merge($project_id, $mr_id, $message = null)
*/
public function showComments($project_id, $mr_id)
{
return $this->get($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id).'/comments'));
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/comments'));
}

/**
Expand All @@ -160,7 +160,7 @@ public function showComments($project_id, $mr_id)
*/
public function addComment($project_id, $mr_id, $note)
{
return $this->post($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id).'/comments'), array(
return $this->post($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/comments'), array(
'note' => $note
));
}
Expand All @@ -172,6 +172,6 @@ public function addComment($project_id, $mr_id, $note)
*/
public function changes($project_id, $mr_id)
{
return $this->get($this->getProjectPath($project_id, 'merge_request/'.rawurlencode($mr_id).'/changes'));
return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/changes'));
}
}
6 changes: 3 additions & 3 deletions lib/Gitlab/Api/Milestones.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
*/
public function show($project_id, $milestone_id)
{
return $this->get($this->getProjectPath($project_id, 'milestones/'.rawurlencode($milestone_id)));
return $this->get($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id)));
}

/**
Expand All @@ -44,7 +44,7 @@ public function create($project_id, array $params)
*/
public function update($project_id, $milestone_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'milestones/'.rawurlencode($milestone_id)), $params);
return $this->put($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id)), $params);
}

/**
Expand All @@ -54,6 +54,6 @@ public function update($project_id, $milestone_id, array $params)
*/
public function issues($project_id, $milestone_id)
{
return $this->get($this->getProjectPath($project_id, 'milestones/'.rawurlencode($milestone_id).'/issues'));
return $this->get($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id).'/issues'));
}
}
28 changes: 14 additions & 14 deletions lib/Gitlab/Api/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function owned($page = 1, $per_page = self::PER_PAGE, $order_by = self::O
*/
public function search($query, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT)
{
return $this->get('projects/search/'.rawurlencode($query), array(
return $this->get('projects/search/'.$this->encodePath($query), array(
'page' => $page,
'per_page' => $per_page,
'order_by' => $order_by,
Expand All @@ -80,7 +80,7 @@ public function search($query, $page = 1, $per_page = self::PER_PAGE, $order_by
*/
public function show($project_id)
{
return $this->get('projects/'.rawurlencode($project_id));
return $this->get('projects/'.$this->encodePath($project_id));
}

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

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

/**
Expand All @@ -115,7 +115,7 @@ public function createForUser($user_id, $name, array $params = array())
*/
public function update($project_id, array $params)
{
return $this->put('projects/'.rawurlencode($project_id), $params);
return $this->put('projects/'.$this->encodePath($project_id), $params);
}

/**
Expand All @@ -124,7 +124,7 @@ public function update($project_id, array $params)
*/
public function remove($project_id)
{
return $this->delete('projects/'.rawurlencode($project_id));
return $this->delete('projects/'.$this->encodePath($project_id));
}

/**
Expand All @@ -146,7 +146,7 @@ public function members($project_id, $username_query = null)
*/
public function member($project_id, $user_id)
{
return $this->get($this->getProjectPath($project_id, 'members/'.rawurlencode($user_id)));
return $this->get($this->getProjectPath($project_id, 'members/'.$this->encodePath($user_id)));
}

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ public function hooks($project_id, $page = 1, $per_page = self::PER_PAGE)
*/
public function hook($project_id, $hook_id)
{
return $this->get($this->getProjectPath($project_id, 'hooks/'.rawurlencode($hook_id)));
return $this->get($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)));
}

/**
Expand Down Expand Up @@ -235,7 +235,7 @@ public function addHook($project_id, $url, array $params = array())
*/
public function updateHook($project_id, $hook_id, array $params)
{
return $this->put($this->getProjectPath($project_id, 'hooks/'.rawurlencode($hook_id)), $params);
return $this->put($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)), $params);
}

/**
Expand All @@ -245,7 +245,7 @@ public function updateHook($project_id, $hook_id, array $params)
*/
public function removeHook($project_id, $hook_id)
{
return $this->delete($this->getProjectPath($project_id, 'hooks/'.rawurlencode($hook_id)));
return $this->delete($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)));
}

/**
Expand All @@ -264,7 +264,7 @@ public function keys($project_id)
*/
public function key($project_id, $key_id)
{
return $this->get($this->getProjectPath($project_id, 'keys/'.rawurlencode($key_id)));
return $this->get($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id)));
}

/**
Expand All @@ -288,7 +288,7 @@ public function addKey($project_id, $title, $key)
*/
public function removeKey($project_id, $key_id)
{
return $this->delete($this->getProjectPath($project_id, 'keys/'.rawurlencode($key_id)));
return $this->delete($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id)));
}

/**
Expand Down Expand Up @@ -353,7 +353,7 @@ public function removeLabel($project_id, $name)
*/
public function createForkRelation($project_id, $forked_project_id)
{
return $this->post($this->getProjectPath($project_id, 'fork/'.rawurlencode($forked_project_id)));
return $this->post($this->getProjectPath($project_id, 'fork/'.$this->encodePath($forked_project_id)));
}

/**
Expand All @@ -373,7 +373,7 @@ public function removeForkRelation($project_id)
*/
public function setService($project_id, $service_name, array $params = array())
{
return $this->put($this->getProjectPath($project_id, 'services/'.rawurlencode($service_name)), $params);
return $this->put($this->getProjectPath($project_id, 'services/'.$this->encodePath($service_name)), $params);
}

/**
Expand All @@ -383,6 +383,6 @@ public function setService($project_id, $service_name, array $params = array())
*/
public function removeService($project_id, $service_name)
{
return $this->delete($this->getProjectPath($project_id, 'services/'.rawurlencode($service_name)));
return $this->delete($this->getProjectPath($project_id, 'services/'.$this->encodePath($service_name)));
}
}
Loading

0 comments on commit 2b320f7

Please sign in to comment.