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 14c3555

Browse filesBrowse files
committed
bug #35480 [Messenger] Check for all serialization exceptions during message dec… (Patrick Berenschot)
This PR was merged into the 4.3 branch. Discussion ---------- [Messenger] Check for all serialization exceptions during message dec… | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35446 | License | MIT Makes it so that the Messenger Serializer throws a `MessageDecodingFailedException` for any serializer exception. Commits ------- 21fffca [Messenger] Check for all serialization exceptions during message dec…
2 parents 5f87c7b + 21fffca commit 14c3555
Copy full SHA for 14c3555

File tree

2 files changed

+36
-3
lines changed
Filter options

2 files changed

+36
-3
lines changed

‎src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,40 @@ public function testEncodedSkipsNonEncodeableStamps()
207207
$encoded = $serializer->encode($envelope);
208208
$this->assertStringNotContainsString('DummySymfonySerializerNonSendableStamp', print_r($encoded['headers'], true));
209209
}
210+
211+
public function testDecodingFailedConstructorDeserialization()
212+
{
213+
$serializer = new Serializer();
214+
215+
$this->expectException(MessageDecodingFailedException::class);
216+
217+
$serializer->decode([
218+
'body' => '{}',
219+
'headers' => ['type' => DummySymfonySerializerInvalidConstructor::class],
220+
]);
221+
}
222+
223+
public function testDecodingStampFailedDeserialization()
224+
{
225+
$serializer = new Serializer();
226+
227+
$this->expectException(MessageDecodingFailedException::class);
228+
229+
$serializer->decode([
230+
'body' => '{"message":"hello"}',
231+
'headers' => [
232+
'type' => DummyMessage::class,
233+
'X-Message-Stamp-'.SerializerStamp::class => '[{}]',
234+
],
235+
]);
236+
}
210237
}
211238
class DummySymfonySerializerNonSendableStamp implements NonSendableStampInterface
212239
{
213240
}
241+
class DummySymfonySerializerInvalidConstructor
242+
{
243+
public function __construct(string $missingArgument)
244+
{
245+
}
246+
}

‎src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\Messenger\Stamp\StampInterface;
2020
use Symfony\Component\Serializer\Encoder\JsonEncoder;
2121
use Symfony\Component\Serializer\Encoder\XmlEncoder;
22-
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
22+
use Symfony\Component\Serializer\Exception\ExceptionInterface;
2323
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
2424
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
2525
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
@@ -81,7 +81,7 @@ public function decode(array $encodedEnvelope): Envelope
8181

8282
try {
8383
$message = $this->serializer->deserialize($encodedEnvelope['body'], $encodedEnvelope['headers']['type'], $this->format, $context);
84-
} catch (UnexpectedValueException $e) {
84+
} catch (ExceptionInterface $e) {
8585
throw new MessageDecodingFailedException(sprintf('Could not decode message: %s.', $e->getMessage()), $e->getCode(), $e);
8686
}
8787

@@ -119,7 +119,7 @@ private function decodeStamps(array $encodedEnvelope): array
119119

120120
try {
121121
$stamps[] = $this->serializer->deserialize($value, substr($name, \strlen(self::STAMP_HEADER_PREFIX)).'[]', $this->format, $this->context);
122-
} catch (UnexpectedValueException $e) {
122+
} catch (ExceptionInterface $e) {
123123
throw new MessageDecodingFailedException(sprintf('Could not decode stamp: %s.', $e->getMessage()), $e->getCode(), $e);
124124
}
125125
}

0 commit comments

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