diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index f824d6516808..8332542a4755 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -95,6 +95,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $allowlist = array('name', 'description', 'author', 'type', 'homepage', 'require', 'require-dev', 'stability', 'license', 'autoload'); $options = array_filter(array_intersect_key($input->getOptions(), array_flip($allowlist))); + if (isset($options['name']) && !preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}D', $options['name'])) { + throw new \InvalidArgumentException( + 'The package name '.$options['name'].' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+' + ); + } + if (isset($options['author'])) { $options['authors'] = $this->formatAuthors($options['author']); unset($options['author']); @@ -273,12 +279,6 @@ protected function interact(InputInterface $input, OutputInterface $output) $name .= '/' . $name; } $name = strtolower($name); - } else { - if (!preg_match('{^[a-z0-9_.-]+/[a-z0-9_.-]+$}D', $name)) { - throw new \InvalidArgumentException( - 'The package name '.$name.' is invalid, it should be lowercase and have a vendor name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+' - ); - } } $name = $io->askAndValidate(