mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #10766 from cakephp/issue-10763
Fix encoding of addreses contain comma & unicode
This commit is contained in:
commit
2b8447dc5b
2 changed files with 30 additions and 5 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue