Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b7f731

Browse files
Feedback
1 parent 5be4490 commit 9b7f731

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/AmazonSqsSerializerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testDecodingFailsWithMissingBodyKey()
3636
$serializer = new AmazonSqsSerializer();
3737

3838
$this->expectException(MessageDecodingFailedException::class);
39-
$this->expectExceptionMessage('Encoded envelope should have at least a "body", or maybe you should implement your own serializer');
39+
$this->expectExceptionMessage('Encoded envelope should have at least a "body"');
4040

4141
$serializer->decode([]);
4242
}

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/AmazonSqsSerializer.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111

1212
namespace Symfony\Component\Messenger\Bridge\AmazonSqs\Transport;
1313

14+
use Symfony\Component\Messenger\Envelope;
1415
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
1516

1617
class AmazonSqsSerializer extends PhpSerializer
1718
{
18-
protected function shouldBeEncoded(string $body): bool
19+
public function encode(Envelope $envelope): array
1920
{
20-
return parent::shouldBeEncoded($body)
21-
|| preg_match('/[^\x20-\x{D7FF}\xA\xD\x9\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', $body);
21+
$encoded = parent::encode($envelope);
22+
if (preg_match('/[^\x20-\x{D7FF}\xA\xD\x9\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', $encoded['body'])) {
23+
$encoded['body'] = base64_encode($encoded['body']);
24+
}
25+
26+
return $encoded;
2227
}
2328
}

src/Symfony/Component/Messenger/Bridge/AmazonSqs/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=7.2.5",
2020
"async-aws/core": "^1.5",
2121
"async-aws/sqs": "^1.0|^2.0",
22-
"symfony/messenger": "^5.4.40|^6.4.8",
22+
"symfony/messenger": "^4.4.19|^5.0|^6.0",
2323
"symfony/service-contracts": "^1.1|^2|^3",
2424
"psr/log": "^1|^2|^3"
2525
},

src/Symfony/Component/Messenger/Transport/Serialization/PhpSerializer.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function encode(Envelope $envelope): array
4141

4242
$body = addslashes(serialize($envelope));
4343

44-
if ($this->shouldBeEncoded($body)) {
44+
if (!preg_match('//u', $body)) {
4545
$body = base64_encode($body);
4646
}
4747

@@ -50,14 +50,6 @@ public function encode(Envelope $envelope): array
5050
];
5151
}
5252

53-
/**
54-
* Entry point to use stricter condition for base64 encoding.
55-
*/
56-
protected function shouldBeEncoded(string $body): bool
57-
{
58-
return !preg_match('//u', $body);
59-
}
60-
6153
private function safelyUnserialize(string $contents)
6254
{
6355
if ('' === $contents) {

0 commit comments

Comments
 (0)