Fix handling of invalid emails
parent
f1ebc1d2b6
commit
28ec4fa7b0
|
@ -479,10 +479,15 @@ EOT
|
|||
*/
|
||||
public function parseAuthorString($author)
|
||||
{
|
||||
if (Preg::isMatch('/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’"()]+)(?: <(?P<email>.+?)>)?$/u', $author, $match)) {
|
||||
if (Preg::isMatch('/^(?P<name>[- .,\p{L}\p{N}\p{Mn}\'’"()]+)(?:\s+<(?P<email>.+?)>)?$/u', $author, $match)) {
|
||||
$hasEmail = isset($match['email']) && '' !== $match['email'];
|
||||
if ($hasEmail && !$this->isValidEmail($match['email'])) {
|
||||
throw new \InvalidArgumentException('Invalid email "'.$match['email'].'"');
|
||||
}
|
||||
|
||||
return array(
|
||||
'name' => trim($match['name']),
|
||||
'email' => (isset($match['email']) && '' !== $match['email'] && $this->isValidEmail($match['email'])) ? $match['email'] : null,
|
||||
'email' => $hasEmail ? $match['email'] : null,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -690,7 +695,7 @@ EOT
|
|||
*/
|
||||
protected function formatAuthors($author)
|
||||
{
|
||||
return array(array_filter($this->parseAuthorString($author)));
|
||||
return array(array_filter($this->parseAuthorString($author), 'is_string'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,14 @@ class InitCommandTest extends TestCase
|
|||
$this->assertEquals('john@example.com', $author['email']);
|
||||
}
|
||||
|
||||
public function testParseValidAuthorStringWithoutEmail()
|
||||
{
|
||||
$command = new InitCommand;
|
||||
$author = $command->parseAuthorString('John Smith');
|
||||
$this->assertEquals('John Smith', $author['name']);
|
||||
$this->assertNull($author['email']);
|
||||
}
|
||||
|
||||
public function testParseValidUtf8AuthorString()
|
||||
{
|
||||
$command = new InitCommand;
|
||||
|
|
Loading…
Reference in New Issue