mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Fix URL resolution for Composer repositories
Composer was unable canonicalize URLs in non-HTTP(S) Composer repositories. For example it was not possible to use a `providers-url` in a repository loaded via the `file://` scheme. See also: #8115
This commit is contained in:
parent
de8368af45
commit
c751914410
2 changed files with 72 additions and 1 deletions
|
@ -204,4 +204,71 @@ class ComposerRepositoryTest extends TestCase
|
|||
$repository->search('foo', RepositoryInterface::SEARCH_FULLTEXT, 'library')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider canonicalizeUrlProvider
|
||||
*
|
||||
* @param string $expected
|
||||
* @param string $url
|
||||
* @param string $repositoryUrl
|
||||
*/
|
||||
public function testCanonicalizeUrl($expected, $url, $repositoryUrl)
|
||||
{
|
||||
$repository = new ComposerRepository(
|
||||
array('url' => $repositoryUrl),
|
||||
new NullIO(),
|
||||
FactoryMock::createConfig()
|
||||
);
|
||||
|
||||
$object = new \ReflectionObject($repository);
|
||||
|
||||
$method = $object->getMethod('canonicalizeUrl');
|
||||
$method->setAccessible(true);
|
||||
|
||||
// ComposerRepository::__construct ensures that the repository URL has a
|
||||
// protocol, so reset it here in order to test all cases.
|
||||
$property = $object->getProperty('url');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($repository, $repositoryUrl);
|
||||
|
||||
$this->assertSame($expected, $method->invoke($repository, $url));
|
||||
}
|
||||
|
||||
public function canonicalizeUrlProvider()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'https://example.org/path/to/file',
|
||||
'/path/to/file',
|
||||
'https://example.org',
|
||||
),
|
||||
array(
|
||||
'https://example.org/canonic_url',
|
||||
'https://example.org/canonic_url',
|
||||
'https://should-not-see-me.test',
|
||||
),
|
||||
array(
|
||||
'file:///path/to/repository/file',
|
||||
'/path/to/repository/file',
|
||||
'file:///path/to/repository',
|
||||
),
|
||||
array(
|
||||
// Assert that the repository URL is returned unchanged if it is
|
||||
// not a URL.
|
||||
// (Backward compatibility test)
|
||||
'invalid_repo_url',
|
||||
'/path/to/file',
|
||||
'invalid_repo_url',
|
||||
),
|
||||
array(
|
||||
// Assert that URLs can contain sequences resembling pattern
|
||||
// references as understood by preg_replace() without messing up
|
||||
// the result.
|
||||
// (Regression test)
|
||||
'https://example.org/path/to/unusual_$0_filename',
|
||||
'/path/to/unusual_$0_filename',
|
||||
'https://example.org',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue