From ac41bb06155fb45a56761faa0cf7b9b0cafd891e Mon Sep 17 00:00:00 2001 From: "Matthew \"Juniper\" Barlett" Date: Wed, 31 Aug 2016 01:29:22 -0500 Subject: [PATCH] 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() {