From 862a13a17ed454f9e7311d3aeecdb72d2a07f48c Mon Sep 17 00:00:00 2001 From: Calin Marian Date: Fri, 8 Jul 2016 16:32:57 +0300 Subject: [PATCH] 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. --- src/Composer/Repository/Vcs/GitLabDriver.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index d542e23d5..1b33612ea 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -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; } /**