Skip to content

Commit 5658dd1

Browse files
committed
Reorganizing messenger serializer config and replacing base64_encode with addslashes
1 parent c101a90 commit 5658dd1

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Tests/Transport/Serialization/PhpSerializerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public function testEncodedIsDecodable()
2525

2626
$envelope = new Envelope(new DummyMessage('Hello'));
2727

28-
$this->assertEquals($envelope, $serializer->decode($serializer->encode($envelope)));
28+
$encoded = $serializer->encode($envelope);
29+
$this->assertNotContains("\0", $encoded['body'], 'Does not contain the binary characters');
30+
$this->assertEquals($envelope, $serializer->decode($encoded));
2931
}
3032

3133
public function testDecodingFailsWithMissingBodyKey()
@@ -58,7 +60,7 @@ public function testDecodingFailsWithBadClass()
5860
$serializer = new PhpSerializer();
5961

6062
$serializer->decode([
61-
'body' => base64_encode('O:13:"ReceivedSt0mp":0:{}'),
63+
'body' => 'O:13:"ReceivedSt0mp":0:{}',
6264
]);
6365
}
6466
}

Transport/Serialization/PhpSerializer.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ public function decode(array $encodedEnvelope): Envelope
3030
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body".');
3131
}
3232

33-
$serializeEnvelope = base64_decode($encodedEnvelope['body']);
34-
35-
if (false === $serializeEnvelope) {
36-
throw new MessageDecodingFailedException('The "body" key could not be base64 decoded.');
37-
}
33+
$serializeEnvelope = stripslashes($encodedEnvelope['body']);
3834

3935
return $this->safelyUnserialize($serializeEnvelope);
4036
}
@@ -44,8 +40,10 @@ public function decode(array $encodedEnvelope): Envelope
4440
*/
4541
public function encode(Envelope $envelope): array
4642
{
43+
$body = addslashes(serialize($envelope));
44+
4745
return [
48-
'body' => base64_encode(serialize($envelope)),
46+
'body' => $body,
4947
];
5048
}
5149

0 commit comments

Comments
 (0)