1
0
Fork 0

Fix handling of invalid emails

pull/10516/head
Jordi Boggiano 2022-02-16 13:24:15 +01:00
parent f1ebc1d2b6
commit 28ec4fa7b0
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 16 additions and 3 deletions

View File

@ -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'));
}
/**

View File

@ -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;