From 8618f004f791144dc33a196a5e5346ab56f77f7b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 12 Oct 2022 16:16:31 +0200 Subject: [PATCH] Fix parsing of aliases used within complex OR constraints, fixes #11086 --- .../Package/Loader/RootPackageLoader.php | 2 +- .../alias-in-complex-constraints.test | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Fixtures/installer/alias-in-complex-constraints.test diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index ffb553671..a1df59622 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -193,7 +193,7 @@ class RootPackageLoader extends ArrayLoader private function extractAliases(array $requires, array $aliases): array { foreach ($requires as $reqName => $reqVersion) { - if (Preg::isMatch('{^([^,\s#]+)(?:#[^ ]+)? +as +([^,\s]+)$}', $reqVersion, $match)) { + if (Preg::isMatch('{(?:^|\| *|, *)([^,\s#|]+)(?:#[^ ]+)? +as +([^,\s|]+)(?:$| *\|| *,)}', $reqVersion, $match)) { $aliases[] = [ 'package' => strtolower($reqName), 'version' => $this->versionParser->normalize($match[1], $reqVersion), diff --git a/tests/Composer/Test/Fixtures/installer/alias-in-complex-constraints.test b/tests/Composer/Test/Fixtures/installer/alias-in-complex-constraints.test new file mode 100644 index 000000000..de6835880 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/alias-in-complex-constraints.test @@ -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)