Skip to content

Commit

Permalink
Move name validation out of interact, fixes #9986
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jun 27, 2021
1 parent e87a150 commit 420d9bf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Composer/Command/InitCommand.php
Expand Up @@ -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']);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 420d9bf

Please sign in to comment.