diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 74059dee6..dc33f6457 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -320,7 +320,7 @@ EOT */ public function parseAuthorString($author) { - if (preg_match('/^(?P[- \.,\p{L}\p{N}\'’]+) <(?P.+?)>$/u', $author, $match)) { + if (preg_match('/^(?P[- .,\p{L}\p{N}\'’"()]+) <(?P.+?)>$/u', $author, $match)) { if ($this->isValidEmail($match['email'])) { return array( 'name' => trim($match['name']), diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index bf221a125..49e82f06c 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -1137,6 +1137,10 @@ class Installer private function updateInstallReferences(PackageInterface $package, $reference) { + if (!$reference) { + return; + } + $package->setSourceReference($reference); $package->setDistReference($reference); diff --git a/tests/Composer/Test/Command/InitCommandTest.php b/tests/Composer/Test/Command/InitCommandTest.php index 7795a4674..80e7935d3 100644 --- a/tests/Composer/Test/Command/InitCommandTest.php +++ b/tests/Composer/Test/Command/InitCommandTest.php @@ -17,6 +17,7 @@ use Composer\TestCase; class InitCommandTest extends TestCase { + public function testParseValidAuthorString() { $command = new InitCommand; @@ -40,6 +41,32 @@ class InitCommandTest extends TestCase $this->assertEquals('h4x0r', $author['name']); $this->assertEquals('h4x@example.com', $author['email']); } + + /** + * Test scenario for issue #5631 + * @link https://github.com/composer/composer/issues/5631 Issue #5631 + */ + public function testParseValidAlias1AuthorString() + { + $command = new InitCommand; + $author = $command->parseAuthorString( + 'Johnathon "Johnny" Smith '); + $this->assertEquals('Johnathon "Johnny" Smith', $author['name'] ); + $this->assertEquals('john@example.com', $author['email']); + } + + /** + * Test scenario for issue #5631 + * @link https://github.com/composer/composer/issues/5631 Issue #5631 + */ + public function testParseValidAlias2AuthorString() + { + $command = new InitCommand; + $author = $command->parseAuthorString( + 'Johnathon (Johnny) Smith '); + $this->assertEquals('Johnathon (Johnny) Smith', $author['name'] ); + $this->assertEquals('john@example.com', $author['email']); + } public function testParseEmptyAuthorString() {