GitHubDriver: stricter URL validation to avoid issues with undefined index owner (#10985)
parent
b0674c421a
commit
1f0bd51f55
|
@ -59,7 +59,7 @@ class GitHubDriver extends VcsDriver
|
||||||
*/
|
*/
|
||||||
public function initialize()
|
public function initialize()
|
||||||
{
|
{
|
||||||
if (!Preg::isMatch('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/(.+?)(?:\.git|/)?$#', $this->url, $match)) {
|
if (!Preg::isMatch('#^(?:(?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#', $this->url, $match)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The GitHub repository URL %s is invalid.', $this->url));
|
throw new \InvalidArgumentException(sprintf('The GitHub repository URL %s is invalid.', $this->url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ class GitHubDriver extends VcsDriver
|
||||||
*/
|
*/
|
||||||
public static function supports(IOInterface $io, Config $config, $url, $deep = false)
|
public static function supports(IOInterface $io, Config $config, $url, $deep = false)
|
||||||
{
|
{
|
||||||
if (!Preg::isMatch('#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/(.+?)(?:\.git|/)?$#', $url, $matches)) {
|
if (!Preg::isMatch('#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#', $url, $matches)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -342,14 +342,16 @@ class GitHubDriverTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @dataProvider invalidUrlProvider
|
||||||
|
* @param string $url
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function initializeInvalidReoUrl()
|
public function testInitializeInvalidReoUrl($url)
|
||||||
{
|
{
|
||||||
$this->setExpectedException('\InvalidArgumentException');
|
$this->setExpectedException('\InvalidArgumentException');
|
||||||
|
|
||||||
$repoConfig = array(
|
$repoConfig = array(
|
||||||
'url' => 'https://github.com/acme',
|
'url' => $url,
|
||||||
);
|
);
|
||||||
|
|
||||||
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
||||||
|
@ -361,6 +363,18 @@ class GitHubDriverTest extends TestCase
|
||||||
$gitHubDriver->initialize();
|
$gitHubDriver->initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{bool, string}>
|
||||||
|
*/
|
||||||
|
public function invalidUrlProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(false, 'https://github.com/acme'),
|
||||||
|
array(false, 'https://github.com/acme/repository/releases'),
|
||||||
|
array(false, 'https://github.com/acme/repository/pulls'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider supportsProvider
|
* @dataProvider supportsProvider
|
||||||
* @param bool $expected
|
* @param bool $expected
|
||||||
|
@ -382,6 +396,8 @@ class GitHubDriverTest extends TestCase
|
||||||
array(false, 'https://github.com/acme'),
|
array(false, 'https://github.com/acme'),
|
||||||
array(true, 'https://github.com/acme/repository'),
|
array(true, 'https://github.com/acme/repository'),
|
||||||
array(true, 'git@github.com:acme/repository.git'),
|
array(true, 'git@github.com:acme/repository.git'),
|
||||||
|
array(false, 'https://github.com/acme/repository/releases'),
|
||||||
|
array(false, 'https://github.com/acme/repository/pulls'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue