Merge pull request #10766 from cakephp/issue-10763

Fix encoding of addreses contain comma & unicode
This commit is contained in:
Mark Story 2017-06-16 21:37:54 -04:00 committed by GitHub
commit 2b8447dc5b
2 changed files with 30 additions and 5 deletions

View file

@ -830,7 +830,10 @@ class CakeEmail {
$return[] = $email;
} else {
$encoded = $this->_encode($alias);
if ($encoded === $alias && preg_match('/[^a-z0-9 ]/i', $encoded)) {
if (
$encoded === $alias && preg_match('/[^a-z0-9 ]/i', $encoded) ||
strpos($encoded, ',') !== false
) {
$encoded = '"' . str_replace('"', '\"', $encoded) . '"';
}
$return[] = sprintf('%s <%s>', $encoded, $email);

View file

@ -450,10 +450,6 @@ class CakeEmailTest extends CakeTestCase {
$expected = array('CakePHP <cake@cakephp.org>', 'Cake <php@cakephp.org>');
$this->assertSame($expected, $result);
$result = $this->CakeEmail->formatAddress(array('me@example.com' => 'Last, First'));
$expected = array('"Last, First" <me@example.com>');
$this->assertSame($expected, $result);
$result = $this->CakeEmail->formatAddress(array('me@example.com' => '"Last" First'));
$expected = array('"\"Last\" First" <me@example.com>');
$this->assertSame($expected, $result);
@ -471,6 +467,32 @@ class CakeEmailTest extends CakeTestCase {
$this->assertSame($expected, $result);
}
/**
* Test that addresses are quoted correctly when they contain unicode and
* commas
*
* @return void
*/
public function testFormatAddressEncodeAndEscape() {
$result = $this->CakeEmail->formatAddress(array(
'test@example.com' => 'Website, ascii'
));
$expected = array('"Website, ascii" <test@example.com>');
$this->assertSame($expected, $result);
$result = $this->CakeEmail->formatAddress(array(
'test@example.com' => 'Wébsite, unicode'
));
$expected = array('=?UTF-8?B?V8OpYnNpdGUsIHVuaWNvZGU=?= <test@example.com>');
$this->assertSame($expected, $result);
$result = $this->CakeEmail->formatAddress(array(
'test@example.com' => 'Website, électric'
));
$expected = array('"Website, =?UTF-8?B?w6lsZWN0cmlj?=" <test@example.com>');
$this->assertSame($expected, $result);
}
/**
* testFormatAddressJapanese
*