From 862a13a17ed454f9e7311d3aeecdb72d2a07f48c Mon Sep 17 00:00:00 2001 From: Calin Marian Date: Fri, 8 Jul 2016 16:32:57 +0300 Subject: [PATCH 1/4] 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; } /** From a888b082b05cfbe78971bf192e1b49ad337b0f08 Mon Sep 17 00:00:00 2001 From: Calin Marian Date: Fri, 8 Jul 2016 17:34:44 +0300 Subject: [PATCH 2/4] Make urlEncodeAll private --- src/Composer/Repository/Vcs/GitLabDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 1b33612ea..f9e6418e5 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -237,7 +237,7 @@ class GitLabDriver extends VcsDriver * @param string $string * @return string */ - protected function urlEncodeAll($string) + private function urlEncodeAll($string) { $encoded = ''; for ($i = 0; isset($string[$i]); $i++) { From f78f6c963d6c4779a577abd4bfc47410ff7b858a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 12 Sep 2016 14:27:04 +0200 Subject: [PATCH 3/4] Add note about rawurlencode, refs #5503 --- src/Composer/Repository/Vcs/GitLabDriver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index f9e6418e5..20dbd38fd 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -232,8 +232,8 @@ class GitLabDriver extends VcsDriver } /** - * Urlencode all non alphanumeric characters. - * + * Urlencode all non alphanumeric characters. rawurlencode() can not be used as it does not encode `.` + * * @param string $string * @return string */ From ff7daf0bd42391a97043d5b6f99c89e2246dba01 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 12 Sep 2016 16:56:04 +0200 Subject: [PATCH 4/4] Fix handling of paths on windows when cwd is root of drive, fixes #5554 --- src/Composer/Util/Filesystem.php | 3 ++- tests/Composer/Test/Util/FilesystemTest.php | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 847f8d8ee..2ac6a54fe 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -444,7 +444,8 @@ class Filesystem $prefix = ''; $absolute = false; - if (preg_match('{^([0-9a-z]+:(?://(?:[a-z]:)?)?)}i', $path, $match)) { + // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive: + if (preg_match('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix', $path, $match)) { $prefix = $match[1]; $path = substr($path, strlen($prefix)); } diff --git a/tests/Composer/Test/Util/FilesystemTest.php b/tests/Composer/Test/Util/FilesystemTest.php index 17297b916..4e60b0ce9 100644 --- a/tests/Composer/Test/Util/FilesystemTest.php +++ b/tests/Composer/Test/Util/FilesystemTest.php @@ -204,12 +204,18 @@ class FilesystemTest extends TestCase array('../foo', '../foo'), array('c:/foo/bar', 'c:/foo//bar'), array('C:/foo/bar', 'C:/foo/./bar'), + array('C:/foo/bar', 'C://foo//bar'), + array('C:/foo/bar', 'C:///foo//bar'), array('C:/bar', 'C:/foo/../bar'), array('/bar', '/foo/../bar/'), array('phar://c:/Foo', 'phar://c:/Foo/Bar/..'), + array('phar://c:/Foo', 'phar://c:///Foo/Bar/..'), array('phar://c:/', 'phar://c:/Foo/Bar/../../../..'), array('/', '/Foo/Bar/../../../..'), array('/', '/'), + array('/', '//'), + array('/', '///'), + array('/Foo', '///Foo'), array('c:/', 'c:\\'), array('../src', 'Foo/Bar/../../../src'), array('c:../b', 'c:.\\..\\a\\..\\b'),