From 6d9e04c0e907ad35b6542f84aa27cd723f6d8e1e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 30 Nov 2015 14:12:29 +0000 Subject: [PATCH] Tweak regex usage --- src/Composer/Repository/Vcs/GitLabDriver.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index a4db638dc..9fca65b11 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -62,8 +62,7 @@ class GitLabDriver extends VcsDriver */ protected $gitDriver; - const URL_REGEX = '#^((https?)://(.*)/|git@([^:]+):)([^/]+)/(.+?)(?:\.git|/)?$#'; - + const URL_REGEX = '#^(?:(?Phttps?)://(?P.+?)/|git@(?P[^:]+):)(?P[^/]+)/(?P[^/]+?)(?:\.git|/)?$#'; /** * Extracts information from the repository url. @@ -73,14 +72,14 @@ class GitLabDriver extends VcsDriver */ public function initialize() { - if (!preg_match(static::URL_REGEX, $this->url, $match)) { + if (!preg_match(self::URL_REGEX, $this->url, $match)) { throw new \InvalidArgumentException('The URL provided is invalid. It must be the HTTP URL of a GitLab project.'); } - $this->scheme = !empty($match[2]) ? $match[2] : 'https'; - $this->originUrl = !empty($match[3]) ? $match[3] : $match[4]; - $this->owner = $match[5]; - $this->repository = preg_replace('#(\.git)$#', '', $match[6]); + $this->scheme = !empty($match['scheme']) ? $match['scheme'] : 'https'; + $this->originUrl = !empty($match['domain']) ? $match['domain'] : $match['domain2']; + $this->owner = $match['owner']; + $this->repository = preg_replace('#(\.git)$#', '', $match['repo']); $this->cache = new Cache($this->io, $this->config->get('cache-repo-dir').'/'.$this->originUrl.'/'.$this->owner.'/'.$this->repository); @@ -346,12 +345,12 @@ class GitLabDriver extends VcsDriver */ public static function supports(IOInterface $io, Config $config, $url, $deep = false) { - if (!preg_match(static::URL_REGEX, $url, $match)) { + if (!preg_match(self::URL_REGEX, $url, $match)) { return false; } - $scheme = !empty($match[2]) ? $match[2] : 'https'; - $originUrl = !empty($match[3]) ? $match[3] : $match[4]; + $scheme = !empty($match['scheme']) ? $match['scheme'] : 'https'; + $originUrl = !empty($match['domain']) ? $match['domain'] : $match['domain2']; if (!in_array($originUrl, (array) $config->get('gitlab-domains'))) { return false;