From 0fe200d6d950b0774688713be3153bb410eb70b8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 31 Jul 2019 18:01:08 +0200 Subject: [PATCH] Fix origin computation --- src/Composer/Repository/Vcs/GitLabDriver.php | 9 ++++++++- tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index 7b593084f..0d8925bc8 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -495,13 +495,20 @@ class GitLabDriver extends VcsDriver private static function determineOrigin(array $configuredDomains, $guessedDomain, array &$urlParts, $portNumber) { if (in_array($guessedDomain, $configuredDomains) || ($portNumber && in_array($guessedDomain.':'.$portNumber, $configuredDomains))) { + if ($portNumber) { + return $guessedDomain.':'.$portNumber; + } return $guessedDomain; } + if ($portNumber) { + $guessedDomain .= ':'.$portNumber; + } + while (null !== ($part = array_shift($urlParts))) { $guessedDomain .= '/' . $part; - if (in_array($guessedDomain, $configuredDomains) || ($portNumber && in_array(preg_replace('{/}', ':'.$portNumber.'/', $guessedDomain, 1), $configuredDomains))) { + if (in_array($guessedDomain, $configuredDomains) || ($portNumber && in_array(preg_replace('{:\d+}', '', $guessedDomain), $configuredDomains))) { return $guessedDomain; } } diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index a5eb799f2..81e623182 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -207,7 +207,7 @@ JSON; JSON; $this->remoteFilesystem - ->getContents($domain, $apiUrl, false, array()) + ->getContents($domain.':'.$port, $apiUrl, false, array()) ->willReturn(sprintf($projectData, $domain, $port, $namespace)) ->shouldBeCalledTimes(1);