bug #30814 [Messenger] base64_encoding inside PhpSerializer to avoid null characters (weaverryan)
This PR was merged into the 4.3-dev branch.
Discussion
----------
[Messenger] base64_encoding inside PhpSerializer to avoid null characters
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #30805
| License | MIT
| Doc PR | not needed
Hi!
As pointed out in #30805, the `PhpSerializer` creates strings with null bytes. This apparently causes problems on at least some database systems (I didn't notice, but @vincenttouzet did). I also read that, for example, SQS doesn't like null characters. And, in general, because we're sending this data over a transport, `base64_encoding` data is pretty standard.
Does anyone see any downsides?
Cheers!
Commits
-------
fe7ad812c7
base64_encoding inside PhpSerializer to avoid null characters
This commit is contained in:
commit
1a5ab6b750
@ -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:{}'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user