Skip to content

Commit c3facf1

Browse files
committed
bug #57284 [Mime] Fix TextPart using an unknown File (fabpot)
This PR was merged into the 6.4 branch. Discussion ---------- [Mime] Fix TextPart using an unknown File | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #57258 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT Commits ------- a6c8963 [Mime] Fix TextPart using an unknown File
2 parents 9b50a92 + a6c8963 commit c3facf1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Mime\Tests\Part;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mime\Exception\InvalidArgumentException;
1516
use Symfony\Component\Mime\Header\Headers;
1617
use Symfony\Component\Mime\Header\ParameterizedHeader;
1718
use Symfony\Component\Mime\Header\UnstructuredHeader;
@@ -55,6 +56,16 @@ public function testConstructorWithFile()
5556
$this->assertSame('content', implode('', iterator_to_array($p->bodyToIterable())));
5657
}
5758

59+
public function testConstructorWithUnknownFile()
60+
{
61+
$p = new TextPart(new File(\dirname(__DIR__).'/Fixtures/unknown.txt'));
62+
63+
// Exception should be thrown only when the body is accessed
64+
$this->expectException(InvalidArgumentException::class);
65+
$this->expectExceptionMessageMatches('{Failed to open stream}');
66+
$p->getBody();
67+
}
68+
5869
public function testConstructorWithNonStringOrResource()
5970
{
6071
$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