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 aee9d51

Browse filesBrowse files
committed
throw exception if calling Email::from() with no address
1 parent 0db9cf2 commit aee9d51
Copy full SHA for aee9d51

File tree

2 files changed

+12
-0
lines changed
Filter options

2 files changed

+12
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Email.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public function addFrom(...$addresses)
121121
*/
122122
public function from(...$addresses)
123123
{
124+
if (!$addresses) {
125+
throw new LogicException(sprintf('"from()" must be called with at least one address.'));
126+
}
127+
124128
return $this->setListAddressHeaderBody('From', $addresses);
125129
}
126130

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Tests/EmailTest.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Component\Mime\Address;
1717
use Symfony\Component\Mime\Email;
18+
use Symfony\Component\Mime\Exception\LogicException;
1819
use Symfony\Component\Mime\Part\DataPart;
1920
use Symfony\Component\Mime\Part\Multipart\AlternativePart;
2021
use Symfony\Component\Mime\Part\Multipart\MixedPart;
@@ -62,6 +63,13 @@ public function testSender()
6263
$this->assertSame($fabien, $e->getSender());
6364
}
6465

66+
public function testFromWithNoAddress()
67+
{
68+
$e = new Email();
69+
$this->expectException(LogicException::class);
70+
$e->from();
71+
}
72+
6573
public function testFrom()
6674
{
6775
$e = new Email();

0 commit comments

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