Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 39e9158

Browse filesBrowse files
committed
[Mime] Escape commas in address names
1 parent d23b74e commit 39e9158
Copy full SHA for 39e9158

File tree

Expand file treeCollapse file tree

5 files changed

+23
-8
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+23
-8
lines changed

‎src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Amazon/Tests/Transport/SesApiTransportTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public function testSend()
6262
parse_str($options['body'], $content);
6363

6464
$this->assertSame('Hello!', $content['Message_Subject_Data']);
65-
$this->assertSame('Saif Eddin <saif.gmati@symfony.com>', $content['Destination_ToAddresses_member'][0]);
66-
$this->assertSame('Fabien <fabpot@symfony.com>', $content['Source']);
65+
$this->assertSame('"Saif Eddin" <saif.gmati@symfony.com>', $content['Destination_ToAddresses_member'][0]);
66+
$this->assertSame('"Fabien" <fabpot@symfony.com>', $content['Source']);
6767
$this->assertSame('Hello There!', $content['Message_Body_Text_Data']);
6868

6969
$xml = '<SendEmailResponse xmlns="https://email.amazonaws.com/doc/2010-03-31/">

‎src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunApiTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Mailgun/Tests/Transport/MailgunApiTransportTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public function testSend()
8282
}
8383

8484
$this->assertStringContainsString('Hello!', $content);
85-
$this->assertStringContainsString('Saif Eddin <saif.gmati@symfony.com>', $content);
86-
$this->assertStringContainsString('Fabien <fabpot@symfony.com>', $content);
85+
$this->assertStringContainsString('"Saif Eddin" <saif.gmati@symfony.com>', $content);
86+
$this->assertStringContainsString('"Fabien" <fabpot@symfony.com>', $content);
8787
$this->assertStringContainsString('Hello There!', $content);
8888

8989
return new MockResponse(json_encode(['id' => 'foobar']), [

‎src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkApiTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkApiTransportTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public function testSend()
7474
$this->assertStringContainsStringIgnoringCase('X-Postmark-Server-Token: KEY', $options['headers'][1] ?? $options['request_headers'][1]);
7575

7676
$body = json_decode($options['body'], true);
77-
$this->assertSame('Fabien <fabpot@symfony.com>', $body['From']);
78-
$this->assertSame('Saif Eddin <saif.gmati@symfony.com>', $body['To']);
77+
$this->assertSame('"Fabien" <fabpot@symfony.com>', $body['From']);
78+
$this->assertSame('"Saif Eddin" <saif.gmati@symfony.com>', $body['To']);
7979
$this->assertSame('Hello!', $body['Subject']);
8080
$this->assertSame('Hello There!', $body['TextBody']);
8181

‎src/Symfony/Component/Mime/Address.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Address.php
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ public function getEncodedAddress(): string
7777

7878
public function toString(): string
7979
{
80-
return ($n = $this->getName()) ? $n.' <'.$this->getEncodedAddress().'>' : $this->getEncodedAddress();
80+
return ($n = $this->getEncodedName()) ? $n.' <'.$this->getEncodedAddress().'>' : $this->getEncodedAddress();
81+
}
82+
83+
public function getEncodedName(): string
84+
{
85+
if ('' === $this->getName()) {
86+
return '';
87+
}
88+
89+
return sprintf('"%s"', preg_replace('/"/u', '\"', $this->getName()));
8190
}
8291

8392
/**

‎src/Symfony/Component/Mime/Tests/AddressTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Tests/AddressTest.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testConstructor()
2727
$a = new Address('fabien@symfonï.com', 'Fabien');
2828
$this->assertEquals('Fabien', $a->getName());
2929
$this->assertEquals('fabien@symfonï.com', $a->getAddress());
30-
$this->assertEquals('Fabien <fabien@xn--symfon-nwa.com>', $a->toString());
30+
$this->assertEquals('"Fabien" <fabien@xn--symfon-nwa.com>', $a->toString());
3131
$this->assertEquals('fabien@xn--symfon-nwa.com', $a->getEncodedAddress());
3232
}
3333

@@ -153,4 +153,10 @@ public function fromStringProvider()
153153
],
154154
];
155155
}
156+
157+
public function testEncodeNameIfNameContainsCommas()
158+
{
159+
$address = new Address('fabien@symfony.com', 'Fabien, "Potencier');
160+
$this->assertSame('"Fabien, \"Potencier" <fabien@symfony.com>', $address->toString());
161+
}
156162
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.