base64_encoding inside PhpSerializer to avoid null characters

This commit is contained in:
Ryan Weaver 2019-04-01 08:36:54 -04:00
parent 9bcea2e9f4
commit fe7ad812c7
2 changed files with 9 additions and 3 deletions

View File

@ -58,7 +58,7 @@ class PhpSerializerTest extends TestCase
$serializer = new PhpSerializer(); $serializer = new PhpSerializer();
$serializer->decode([ $serializer->decode([
'body' => 'O:13:"ReceivedSt0mp":0:{}', 'body' => base64_encode('O:13:"ReceivedSt0mp":0:{}'),
]); ]);
} }
} }

View File

@ -30,7 +30,13 @@ class PhpSerializer implements SerializerInterface
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body".'); throw new MessageDecodingFailedException('Encoded envelope should have at least a "body".');
} }
return $this->safelyUnserialize($encodedEnvelope['body']); $serializeEnvelope = base64_decode($encodedEnvelope['body']);
if (false === $serializeEnvelope) {
throw new MessageDecodingFailedException('The "body" key could not be base64 decoded.');
}
return $this->safelyUnserialize($serializeEnvelope);
} }
/** /**
@ -39,7 +45,7 @@ class PhpSerializer implements SerializerInterface
public function encode(Envelope $envelope): array public function encode(Envelope $envelope): array
{ {
return [ return [
'body' => serialize($envelope), 'body' => base64_encode(serialize($envelope)),
]; ];
} }