ArrayLoader/ValidatingArrayLoader: handle non-string values for version/version_normalized (#10470)
Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>pull/10477/head
parent
6b8f1409e4
commit
3b4afaa9e3
|
@ -113,12 +113,15 @@ class ArrayLoader implements LoaderInterface
|
||||||
if (!isset($config['name'])) {
|
if (!isset($config['name'])) {
|
||||||
throw new \UnexpectedValueException('Unknown package has no name defined ('.json_encode($config).').');
|
throw new \UnexpectedValueException('Unknown package has no name defined ('.json_encode($config).').');
|
||||||
}
|
}
|
||||||
if (!isset($config['version'])) {
|
if (!isset($config['version']) || !is_scalar($config['version'])) {
|
||||||
throw new \UnexpectedValueException('Package '.$config['name'].' has no version defined.');
|
throw new \UnexpectedValueException('Package '.$config['name'].' has no version defined.');
|
||||||
}
|
}
|
||||||
|
if (!is_string($config['version'])) {
|
||||||
|
$config['version'] = (string) $config['version'];
|
||||||
|
}
|
||||||
|
|
||||||
// handle already normalized versions
|
// handle already normalized versions
|
||||||
if (isset($config['version_normalized'])) {
|
if (isset($config['version_normalized']) && is_string($config['version_normalized'])) {
|
||||||
$version = $config['version_normalized'];
|
$version = $config['version_normalized'];
|
||||||
|
|
||||||
// handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEFAULT_BRANCH_ALIAS, we renormalize it
|
// handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEFAULT_BRANCH_ALIAS, we renormalize it
|
||||||
|
|
|
@ -71,6 +71,12 @@ class ValidatingArrayLoader implements LoaderInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->config['version'])) {
|
if (!empty($this->config['version'])) {
|
||||||
|
if (!is_scalar($this->config['version'])) {
|
||||||
|
$this->validateString('version');
|
||||||
|
} else {
|
||||||
|
if (!is_string($this->config['version'])) {
|
||||||
|
$this->config['version'] = (string) $this->config['version'];
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$this->versionParser->normalize($this->config['version']);
|
$this->versionParser->normalize($this->config['version']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -78,6 +84,7 @@ class ValidatingArrayLoader implements LoaderInterface
|
||||||
unset($this->config['version']);
|
unset($this->config['version']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($this->config['config']['platform'])) {
|
if (!empty($this->config['config']['platform'])) {
|
||||||
foreach ((array) $this->config['config']['platform'] as $key => $platform) {
|
foreach ((array) $this->config['config']['platform'] as $key => $platform) {
|
||||||
|
|
|
@ -314,4 +314,15 @@ class ArrayLoaderTest extends TestCase
|
||||||
$this->assertArrayHasKey('composer-plugin-api', $links);
|
$this->assertArrayHasKey('composer-plugin-api', $links);
|
||||||
$this->assertSame('6.6.6', $links['composer-plugin-api']->getConstraint()->getPrettyString());
|
$this->assertSame('6.6.6', $links['composer-plugin-api']->getConstraint()->getPrettyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNoneStringVersion()
|
||||||
|
{
|
||||||
|
$config = array(
|
||||||
|
'name' => 'acme/package',
|
||||||
|
'version' => 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
$package = $this->loader->load($config);
|
||||||
|
$this->assertSame('1', $package->getPrettyVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue