From 7cca45131293a3825ac378d60e38283e4794ea89 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 13 Mar 2020 13:52:16 +0100 Subject: [PATCH] Fix more issues with dev-master normalization in aliases --- src/Composer/Package/AliasPackage.php | 12 ++++++++++-- src/Composer/Package/Loader/ArrayLoader.php | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index 1debf3e30..3e117f7d9 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -173,19 +173,27 @@ class AliasPackage extends BasePackage implements CompletePackageInterface */ protected function replaceSelfVersionDependencies(array $links, $linkType) { + // for self.version requirements, we use the original package's branch name instead of 9999999-dev, to avoid leaking 9999999-dev to users + $prettyVersion = $this->prettyVersion; + if ($prettyVersion === '9999999-dev') { + $prettyVersion = $this->aliasOf->getPrettyVersion(); + } + if (in_array($linkType, array('conflicts', 'provides', 'replaces'), true)) { $newLinks = array(); foreach ($links as $link) { // link is self.version, but must be replacing also the replaced version if ('self.version' === $link->getPrettyConstraint()) { - $newLinks[] = new Link($link->getSource(), $link->getTarget(), new Constraint('=', $this->version), $linkType, $this->prettyVersion); + $newLinks[] = new Link($link->getSource(), $link->getTarget(), $constraint = new Constraint('=', $this->version), $linkType, $prettyVersion); + $constraint->setPrettyString($prettyVersion); } } $links = array_merge($links, $newLinks); } else { foreach ($links as $index => $link) { if ('self.version' === $link->getPrettyConstraint()) { - $links[$index] = new Link($link->getSource(), $link->getTarget(), new Constraint('=', $this->version), $linkType, $this->prettyVersion); + $links[$index] = new Link($link->getSource(), $link->getTarget(), $constraint = new Constraint('=', $this->version), $linkType, $prettyVersion); + $constraint->setPrettyString($prettyVersion); } } } diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index a9ddabf7d..2b31db793 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -247,11 +247,13 @@ class ArrayLoader implements LoaderInterface } if ($aliasNormalized = $this->getBranchAlias($config)) { + $prettyAlias = preg_replace('{(\.9{7})+}', '.x', $aliasNormalized); + if ($package instanceof RootPackageInterface) { - return new RootAliasPackage($package, $aliasNormalized, preg_replace('{(\.9{7})+}', '.x', $aliasNormalized)); + return new RootAliasPackage($package, $aliasNormalized, $prettyAlias); } - return new AliasPackage($package, $aliasNormalized, preg_replace('{(\.9{7})+}', '.x', $aliasNormalized)); + return new AliasPackage($package, $aliasNormalized, $prettyAlias); } return $package;