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 2596a1f

Browse filesBrowse files
bug #48156 [Mime] When serializing File parts convert to string to allow proper unserialization (ovrflo)
This PR was merged into the 6.2 branch. Discussion ---------- [Mime] When serializing File parts convert to string to allow proper unserialization | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47991 | License | MIT I took a stab at #47991. I found an existing serialization test and added the missing case, for regression purposes. The bug was a `\BadMethodCallException` thrown in `\Symfony\Component\Mime\Part\DataPart::__wakeup` when it would encounter a `File` instance instead of a `string`. My fix comes with the implication that, when serializing a `TextPart` with a `File`, it will read and serialize the content of the file, discarding the `File` instance in the process. The assumption being that the machine producing a serialized message might not be the machine consuming that message. Commits ------- 33408bc [Mime] When serializing File parts convert to string to to allow proper unserialization. Fixes #47991.
2 parents 91b2bca + 33408bc commit 2596a1f
Copy full SHA for 2596a1f

File tree

2 files changed

+2
-1
lines changed
Filter options

2 files changed

+2
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Part/TextPart.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private function chooseEncoding(): string
218218
public function __sleep(): array
219219
{
220220
// convert resources to strings for serialization
221-
if (null !== $this->seekable) {
221+
if (null !== $this->seekable || $this->body instanceof File) {
222222
$this->body = $this->getBody();
223223
$this->seekable = null;
224224
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Tests/EmailTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ public function testSerialize()
483483
$name = __DIR__.'/Fixtures/mimetypes/test';
484484
$file = fopen($name, 'r');
485485
$e->addPart(new DataPart($file, 'test'));
486+
$e->attachFromPath($name, 'same_test');
486487
$expected = clone $e;
487488
$n = unserialize(serialize($e));
488489
$this->assertEquals($expected->getHeaders(), $n->getHeaders());

0 commit comments

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