Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayLoader: handle links where target is invalid numeric package name #10663

Merged
merged 1 commit into from Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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