1
0
Fork 0

Do not apply non-string package link constraints in ArrayLoader (#11009)

pull/11008/head
Zan Baldwin 2022-08-20 08:34:38 +02:00 committed by GitHub
parent 7ccf230390
commit 51774693c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -364,6 +364,9 @@ class ArrayLoader implements LoaderInterface
{ {
$res = []; $res = [];
foreach ($links as $target => $constraint) { foreach ($links as $target => $constraint) {
if (!is_string($constraint)) {
continue;
}
$target = strtolower((string) $target); $target = strtolower((string) $target);
$res[$target] = $this->createLink($source, $sourceVersion, $description, $target, $constraint); $res[$target] = $this->createLink($source, $sourceVersion, $description, $target, $constraint);
} }

View File

@ -371,4 +371,35 @@ class ArrayLoaderTest extends TestCase
$this->assertNull($this->loader->getBranchAlias($config)); $this->assertNull($this->loader->getBranchAlias($config));
} }
public function testPackageLinksRequire(): void
{
$config = array(
'name' => 'acme/package',
'version' => 'dev-1',
'require' => [
'foo/bar' => '1.0',
],
);
$package = $this->loader->load($config);
$this->assertArrayHasKey('foo/bar', $package->getRequires());
$this->assertSame('1.0', $package->getRequires()['foo/bar']->getConstraint()->getPrettyString());
}
public function testPackageLinksRequireInvalid(): void
{
$config = array(
'name' => 'acme/package',
'version' => 'dev-1',
'require' => [
'foo/bar' => [
'random-string' => '1.0',
],
],
);
$package = $this->loader->load($config);
$this->assertCount(0, $package->getRequires());
}
} }