From 960fa4b205bc336caac3b15d437e2662764c87f8 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 10 Apr 2020 16:27:37 +0200 Subject: [PATCH 1/2] Allow duplicate dashes in package names fixes #8749 1.10 implementation of #8750 --- .../Package/Loader/ValidatingArrayLoader.php | 4 +- .../Loader/ValidatingArrayLoaderTest.php | 64 ++++++++++++++++--- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index f02f6b165..ad2344187 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -374,8 +374,8 @@ class ValidatingArrayLoader implements LoaderInterface return; } - if (!preg_match('{^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*$}iD', $name)) { - return $name.' is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*".'; + if (!preg_match('{^[a-z0-9](?:[_.-]?[a-z0-9]+)*/[a-z0-9](?:(?:[_.]?|-{0,2})[a-z0-9]+)*$}iD', $name)) { + return $name.' is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$".'; } $reservedNames = array('nul', 'con', 'prn', 'aux', 'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9'); diff --git a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php index 2cde001ac..9dabb23b7 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php @@ -173,6 +173,26 @@ class ValidatingArrayLoaderTest extends TestCase 'bin' => 'bin1', ), ), + array( // package name with dashes + array( + 'name' => 'foo/bar-baz', + ), + ), + array( // package name with dashes + array( + 'name' => 'foo/bar--baz', + ), + ), + array( // package name with dashes + array( + 'name' => 'foo/b-ar--ba-z', + ), + ), + array( // package name with dashes + array( + 'name' => 'npm-asset/angular--core', + ), + ), ); } @@ -232,15 +252,24 @@ class ValidatingArrayLoaderTest extends TestCase public function errorProvider() { - return array( - array( + $invalidNames = array( + 'foo', + 'foo/-bar-', + 'foo/-bar', + ); + $invalidNaming = array(); + foreach($invalidNames as $invalidName) { + $invalidNaming[] = array( array( - 'name' => 'foo', + 'name' => $invalidName, ), array( - 'name : invalid value (foo), must match [A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9][A-Za-z0-9_.-]*', + "name : invalid value ($invalidName), must match [A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9][A-Za-z0-9_.-]*", ), - ), + ); + } + + return array_merge($invalidNaming, array( array( array( 'name' => 'foo/bar', @@ -292,12 +321,31 @@ class ValidatingArrayLoaderTest extends TestCase 'transport-options : should be an array, string given', ), ), - ); + )); } public function warningProvider() { - return array( + $invalidNames = array( + 'fo--oo/bar', + 'fo-oo/bar__baz', + 'fo-oo/bar_.baz', + 'foo/bar---baz', + ); + $invalidNaming = array(); + foreach($invalidNames as $invalidName) { + $invalidNaming[] = array( + array( + 'name' => $invalidName, + ), + array( + "Deprecation warning: Your package name $invalidName is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match \"^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$\". Make sure you fix this as Composer 2.0 will error.", + ), + false, + ); + } + + return array_merge($invalidNaming, array( array( array( 'name' => 'foo/bar', @@ -422,6 +470,6 @@ class ValidatingArrayLoaderTest extends TestCase ), false, ), - ); + )); } } From c718579623f695cca148ed4ada38d5bc395a83b9 Mon Sep 17 00:00:00 2001 From: Fabien Villepinte Date: Sun, 12 Apr 2020 14:35:23 +0200 Subject: [PATCH 2/2] Dispatch POST_STATUS_CMD even when there is no changes --- src/Composer/Command/StatusCommand.php | 28 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 116d5b99e..6d836d2bf 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -65,20 +65,37 @@ EOT */ protected function execute(InputInterface $input, OutputInterface $output) { - // init repos $composer = $this->getComposer(); $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'status', $input, $output); $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent); + // Dispatch pre-status-command + $composer->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_STATUS_CMD, true); + + $exitCode = $this->doExecute($input, $output); + + // Dispatch post-status-command + $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_STATUS_CMD, true); + + return $exitCode; + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int + */ + private function doExecute(InputInterface $input, OutputInterface $output) + { + // init repos + $composer = $this->getComposer(); + $installedRepo = $composer->getRepositoryManager()->getLocalRepository(); $dm = $composer->getDownloadManager(); $im = $composer->getInstallationManager(); - // Dispatch pre-status-command - $composer->getEventDispatcher()->dispatchScript(ScriptEvents::PRE_STATUS_CMD, true); - $errors = array(); $io = $this->getIO(); $unpushedChanges = array(); @@ -206,9 +223,6 @@ EOT $io->writeError('Use --verbose (-v) to see a list of files'); } - // Dispatch post-status-command - $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_STATUS_CMD, true); - return ($errors ? self::EXIT_CODE_ERRORS : 0) + ($unpushedChanges ? self::EXIT_CODE_UNPUSHED_CHANGES : 0) + ($vcsVersionChanges ? self::EXIT_CODE_VERSION_CHANGES : 0); } }