Skip to content

Commit 68afdb8

Browse files
committed
[Mime] Fix TextPart using an unknown File
1 parent d9367f9 commit 68afdb8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Component/Mime/Part/TextPart.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ public function getName(): ?string
123123
public function getBody(): string
124124
{
125125
if ($this->body instanceof File) {
126-
return file_get_contents($this->body->getPath());
126+
if (false === $ret = @file_get_contents($this->body->getPath())) {
127+
throw new InvalidArgumentException(error_get_last()['message']);
128+
}
129+
130+
return $ret;
127131
}
128132

129133
if (null === $this->seekable) {

src/Symfony/Component/Mime/Tests/Part/TextPartTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public function testConstructorWithFile()
5555
$this->assertSame('content', implode('', iterator_to_array($p->bodyToIterable())));
5656
}
5757

58+
public function testConstructorWithUnknownFile()
59+
{
60+
$p = new TextPart(new File(\dirname(__DIR__).'/Fixtures/unknown.txt'));
61+
62+
// Exception should be thrown only when the body is accessed
63+
$this->expectException(InvalidArgumentException::class);
64+
$this->expectExceptionMessageMatches('{Failed to open stream}');
65+
$p->getBody();
66+
}
67+
5868
public function testConstructorWithNonStringOrResource()
5969
{
6070
$this->expectException(\TypeError::class);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy