8000 bug #38433 [Mime] Fix serialization of RawMessage (gilbertsoft) · symfony/symfony@87f3284 · GitHub
[go: up one dir, main page]

Skip to content

Commit 87f3284

Browse files
committed
bug #38433 [Mime] Fix serialization of RawMessage (gilbertsoft)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Mime] Fix serialization of RawMessage | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #38430, Related #33394 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | - <!-- required for new features --> The serialization of RawMessage is currently broken if using a generator for message like done by `Symfony\Component\Mailer\SentMessage` see https://github.com/symfony/symfony/blob/5f1c3a797247a6d54992384df00bb22741fc1c34/src/Symfony/Component/Mailer/SentMessage.php#L45 This patch converts the message to a string so further serialization can be done. This patch probably also solves #33394. <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. --> Commits ------- fd99eb2 [Mime] Fix serialization of RawMessage
2 parents 2f7751f + fd99eb2 commit 87f3284

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Component/Mime/RawMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ final public function unserialize($serialized)
7878

7979
public function __serialize(): array
8080
{
81-
return [$this->message];
81+
return [$this->toString()];
8282
}
8383

8484
public function __unserialize(array $data): void

src/Symfony/Component/Mime/Tests/RawMessageTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,18 @@ public function testToString()
3232
$this->assertEquals('some string', $message->toString());
3333
$this->assertEquals('some string', implode('', iterator_to_array($message->toIterable())));
3434
}
35+
36+
public function testSerialization()
37+
{
38+
$message = new RawMessage('string');
39+
$this->assertEquals('string', unserialize(serialize($message))->toString());
40+
// calling methods more than once work
41+
$this->assertEquals('string', unserialize(serialize($message))->toString());
42+
43+
$message = new RawMessage(new \ArrayObject(['some', ' ', 'string']));
44+
$message = new RawMessage($message->toIterable());
45+
$this->assertEquals('some string', unserialize(serialize($message< 4FE6 /span>))->toString());
46+
// calling methods more than once work
47+
$this->assertEquals('some string', unserialize(serialize($message))->toString());
48+
}
3549
}

0 commit comments

Comments
 (0)
0