Urlencode Gitlab project names

Url encode all non alphanumeric characters in project name for GitLabDriver.

If the project name has "." characters in it, which is supported in Gitlab, the Gitlab API will 404 when requesting the branches or tags of the repository. This commit urlencodes all non alphanumeric characters in the project name in requests to the Gitlab API.
main
Calin Marian 8 years ago committed by Jordi Boggiano
parent 568108da28
commit 862a13a17e

@ -228,7 +228,24 @@ class GitLabDriver extends VcsDriver
*/
public function getApiUrl()
{
return $this->scheme.'://'.$this->originUrl.'/api/v3/projects/'.$this->owner.'%2F'.$this->repository;
return $this->scheme.'://'.$this->originUrl.'/api/v3/projects/'.$this->urlEncodeAll($this->owner).'%2F'.$this->urlEncodeAll($this->repository);
}
/**
* Urlencode all non alphanumeric characters.
*
* @param string $string
* @return string
*/
protected function urlEncodeAll($string)
{
$encoded = '';
for ($i = 0; isset($string[$i]); $i++) {
$character = $string[$i];
if (!ctype_alnum($character)) $character = '%' . sprintf('%02X', ord($character));
$encoded .= $character;
}
return $encoded;
}
/**

Loading…
Cancel
Save