Skip to content

Commit

Permalink
Make sure that names with wildcards which are not preceded by dots ar…
Browse files Browse the repository at this point in the history
…e also seen as package names and not version constraints
  • Loading branch information
Seldaek committed Sep 5, 2021
1 parent 6c9aecf commit dd49db6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Composer/Package/Version/VersionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function parseNameVersionPairs(array $pairs)

for ($i = 0, $count = count($pairs); $i < $count; $i++) {
$pair = preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', trim($pairs[$i]));
if (false === strpos($pair, ' ') && isset($pairs[$i + 1]) && false === strpos($pairs[$i + 1], '/') && !preg_match('{(?<!\.)\*}', $pairs[$i + 1]) && !PlatformRepository::isPlatformPackage($pairs[$i + 1])) {
if (false === strpos($pair, ' ') && isset($pairs[$i + 1]) && false === strpos($pairs[$i + 1], '/') && !preg_match('{(?<=[a-z0-9_/-])\*|\*(?=[a-z0-9_/-])}i', $pairs[$i + 1]) && !PlatformRepository::isPlatformPackage($pairs[$i + 1])) {
$pair .= ' '.$pairs[$i + 1];
$i++;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Composer/Test/Package/Version/VersionParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function getParseNameVersionPairsData()
array(array('php:^7.0'), array(array('name' => 'php', 'version' => '^7.0'))),
array(array('php', '^7.0'), array(array('name' => 'php', 'version' => '^7.0'))),
array(array('php', 'ext-apcu'), array(array('name' => 'php'), array('name' => 'ext-apcu'))),
array(array('foo/*', 'bar*', 'acme/baz', '*@dev'), array(array('name' => 'foo/*'), array('name' => 'bar*'), array('name' => 'acme/baz', 'version' => '*@dev'))),
array(array('php', '*'), array(array('name' => 'php', 'version' => '*'))),
);
}

Expand Down

0 comments on commit dd49db6

Please sign in to comment.