Skip to content

Commit

Permalink
ArrayLoader: handle links where target is invalid numeric package name (
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubinix committed Mar 29, 2022
1 parent 9f8ee0e commit 854aab5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Composer/Package/Loader/ArrayLoader.php
Expand Up @@ -357,10 +357,10 @@ private function configureCachedLinks(array &$linkCache, PackageInterface $packa
}

/**
* @param string $source source package name
* @param string $sourceVersion source package version (pretty version ideally)
* @param string $description link description (e.g. requires, replaces, ..)
* @param array<string, string> $links array of package name => constraint mappings
* @param string $source source package name
* @param string $sourceVersion source package version (pretty version ideally)
* @param string $description link description (e.g. requires, replaces, ..)
* @param array<string|int, string> $links array of package name => constraint mappings
*
* @return Link[]
*
Expand All @@ -370,7 +370,7 @@ public function parseLinks(string $source, string $sourceVersion, string $descri
{
$res = array();
foreach ($links as $target => $constraint) {
$target = strtolower($target);
$target = strtolower((string) $target);
$res[$target] = $this->createLink($source, $sourceVersion, $description, $target, $constraint);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Composer/Test/Package/Loader/ArrayLoaderTest.php
Expand Up @@ -315,6 +315,13 @@ public function testPluginApiVersionDoesSupportSelfVersion(): void
$this->assertSame('6.6.6', $links['composer-plugin-api']->getConstraint()->getPrettyString());
}

public function testParseLinksIntegerTarget(): void
{
$links = $this->loader->parseLinks('Plugin', '9.9.9', Link::TYPE_REQUIRE, array('1' => 'dev-main'));

$this->assertArrayHasKey('1', $links);
}

public function testNoneStringVersion(): void
{
$config = array(
Expand Down

0 comments on commit 854aab5

Please sign in to comment.