From a0c90bad0faf92a655718949229514b9f42dba61 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 28 May 2012 02:37:33 +0200 Subject: [PATCH] Fix normalization in init command with --no-interaction and --require When calling `composer init --no-interaction --require foo/bar:dev-master` it would fail because in non-interactive mode it would only split on space. --- src/Composer/Command/InitCommand.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 988dd0220..e80b43277 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -259,7 +259,7 @@ EOT if ($requires) { foreach ($requires as $key => $requirement) { - $requires[$key] = preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', $requirement); + $requires[$key] = $this->normalizeRequirement($requirement); if (false === strpos($requires[$key], ' ') && $input->isInteractive()) { $question = $dialog->getQuestion('Please provide a version constraint for the '.$requirement.' requirement'); if ($constraint = $dialog->ask($output, $question)) { @@ -328,6 +328,7 @@ EOT { $requires = array(); foreach ($requirements as $requirement) { + $requirement = $this->normalizeRequirement($requirement); list($packageName, $packageVersion) = explode(" ", $requirement, 2); $requires[$packageName] = $packageVersion; @@ -336,6 +337,11 @@ EOT return empty($requires) ? new \stdClass : $requires; } + protected function normalizeRequirement($requirement) + { + return preg_replace('{^([^=: ]+)[=: ](.*)$}', '$1 $2', $requirement); + } + protected function getGitConfig() { if (null !== $this->gitConfig) {