From ed78253c580c753e77dd6ed1e625c3fee1233881 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 2 Sep 2016 18:43:44 +0200 Subject: [PATCH 1/3] Only update reference if there is actually a reference, fixes #5609 --- src/Composer/Installer.php | 4 ++++ 1 file changed, 4 insertions(+) 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); From ac41bb06155fb45a56761faa0cf7b9b0cafd891e Mon Sep 17 00:00:00 2001 From: "Matthew \"Juniper\" Barlett" Date: Wed, 31 Aug 2016 01:29:22 -0500 Subject: [PATCH 2/3] Fix for issue #5631 - Add " ( and ) as valid characters in author name - Add relavent unit tests --- src/Composer/Command/InitCommand.php | 2 +- .../Composer/Test/Command/InitCommandTest.php | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 74059dee6..fe708b18f 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/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() { From 09dad8a0180ae5a6e6eccd7c1507b4127e0bb707 Mon Sep 17 00:00:00 2001 From: "Matthew \"Juniper\" Barlett" Date: Wed, 31 Aug 2016 18:38:10 -0500 Subject: [PATCH 3/3] Clean up regex in InitCommand::parseAuthorString Per comments: - https://github.com/composer/composer/pull/5638#discussion_r76972844 - https://github.com/composer/composer/pull/5638#discussion_r76973941 --- src/Composer/Command/InitCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index fe708b18f..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']),