[Messenger] Fix transporting non-UTF8 payloads by encoding them using base 64
This commit is contained in:
parent
4181c431e9
commit
6fc9e51722
@ -76,6 +76,17 @@ class PhpSerializerTest extends TestCase
|
||||
$encoded = $serializer->encode($envelope);
|
||||
$this->assertStringNotContainsString('DummyPhpSerializerNonSendableStamp', $encoded['body']);
|
||||
}
|
||||
|
||||
public function testNonUtf8IsBase64Encoded()
|
||||
{
|
||||
$serializer = new PhpSerializer();
|
||||
|
||||
$envelope = new Envelope(new DummyMessage("\xE9"));
|
||||
|
||||
$encoded = $serializer->encode($envelope);
|
||||
$this->assertTrue((bool) preg_match('//u', $encoded['body']), 'Encodes non-UTF8 payloads');
|
||||
$this->assertEquals($envelope, $serializer->decode($encoded));
|
||||
}
|
||||
}
|
||||
|
||||
class DummyPhpSerializerNonSendableStamp implements NonSendableStampInterface
|
||||
|
@ -29,6 +29,10 @@ class PhpSerializer implements SerializerInterface
|
||||
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body".');
|
||||
}
|
||||
|
||||
if (false === strpos($encodedEnvelope['body'], '}', -1)) {
|
||||
$encodedEnvelope['body'] = base64_decode($encodedEnvelope['body']);
|
||||
}
|
||||
|
||||
$serializeEnvelope = stripslashes($encodedEnvelope['body']);
|
||||
|
||||
return $this->safelyUnserialize($serializeEnvelope);
|
||||
@ -43,6 +47,10 @@ class PhpSerializer implements SerializerInterface
|
||||
|
||||
$body = addslashes(serialize($envelope));
|
||||
|
||||
if (!preg_match('//u', $body)) {
|
||||
$body = base64_encode($body);
|
||||
}
|
||||
|
||||
return [
|
||||
'body' => $body,
|
||||
];
|
||||
|
Reference in New Issue
Block a user