1
0
Fork 0

Fix parsing of aliases used within complex OR constraints, fixes #11086

pull/11115/head
Jordi Boggiano 2022-10-12 16:16:31 +02:00
parent d06796efcf
commit 8618f004f7
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 59 additions and 1 deletions

View File

@ -193,7 +193,7 @@ class RootPackageLoader extends ArrayLoader
private function extractAliases(array $requires, array $aliases): array private function extractAliases(array $requires, array $aliases): array
{ {
foreach ($requires as $reqName => $reqVersion) { foreach ($requires as $reqName => $reqVersion) {
if (Preg::isMatch('{^([^,\s#]+)(?:#[^ ]+)? +as +([^,\s]+)$}', $reqVersion, $match)) { if (Preg::isMatch('{(?:^|\| *|, *)([^,\s#|]+)(?:#[^ ]+)? +as +([^,\s|]+)(?:$| *\|| *,)}', $reqVersion, $match)) {
$aliases[] = [ $aliases[] = [
'package' => strtolower($reqName), 'package' => strtolower($reqName),
'version' => $this->versionParser->normalize($match[1], $reqVersion), 'version' => $this->versionParser->normalize($match[1], $reqVersion),

View File

@ -0,0 +1,58 @@
--TEST--
Aliases can be extracted out of complex AND or OR constraints
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{
"name": "a/a", "version": "dev-feature-foo",
"source": { "reference": "feat.a", "type": "git", "url": "" }
},
{
"name": "a/b", "version": "dev-feature-foo",
"source": { "reference": "feat.b", "type": "git", "url": "" }
},
{
"name": "a/c", "version": "dev-feature-foo",
"source": { "reference": "feat.c", "type": "git", "url": "" }
},
{
"name": "a/d", "version": "dev-feature-foo",
"source": { "reference": "feat.d", "type": "git", "url": "" }
},
{
"name": "enforcer/pkg", "version": "1.0.0",
"source": { "reference": "feat.c", "type": "git", "url": "" },
"require": {
"a/a": "^1",
"a/b": "^1",
"a/c": "^1",
"a/d": "^1"
}
}
]
}
],
"require": {
"a/a": "1.*||dev-feature-foo as 1.0.2||^2",
"a/b": "dev-feature-foo, dev-feature-foo as 1.0.2",
"a/c": "dev-feature-foo as 1.0.2||^2",
"a/d": "dev-feature-foo as 1.0.2, dev-feature-foo",
"enforcer/pkg": "*"
},
"minimum-stability": "dev"
}
--RUN--
install
--EXPECT--
Installing a/d (dev-feature-foo feat.d)
Marking a/d (1.0.2) as installed, alias of a/d (dev-feature-foo feat.d)
Installing a/c (dev-feature-foo feat.c)
Marking a/c (1.0.2) as installed, alias of a/c (dev-feature-foo feat.c)
Installing a/b (dev-feature-foo feat.b)
Marking a/b (1.0.2) as installed, alias of a/b (dev-feature-foo feat.b)
Installing a/a (dev-feature-foo feat.a)
Marking a/a (1.0.2) as installed, alias of a/a (dev-feature-foo feat.a)
Installing enforcer/pkg (1.0.0)