Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4d0aeed

Browse filesBrowse files
committed
bug #54920 [Messenger] Comply with Amazon SQS requirements for message body (VincentLanglet)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Messenger] Comply with Amazon SQS requirements for message body | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #49844 | License | MIT Commits ------- 0d441bf [Messenger] Comply with Amazon SQS requirements for message body
2 parents ab461c5 + 0d441bf commit 4d0aeed
Copy full SHA for 4d0aeed

File tree

2 files changed

+32
-0
lines changed
Filter options

2 files changed

+32
-0
lines changed

‎src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/AmazonSqsSenderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/AmazonSqsSenderTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,19 @@ public function testSendWithAmazonSqsXrayTraceHeaderStamp()
7272
$sender = new AmazonSqsSender($connection, $serializer);
7373
$sender->send($envelope);
7474
}
75+
76+
public function testSendEncodeBodyToRespectAmazonRequirements()
77+
{
78+
$envelope = new Envelope(new DummyMessage('Oy'));
79+
$encoded = ['body' => "\x7", 'headers' => ['type' => DummyMessage::class]];
80+
81+
$connection = $this->createMock(Connection::class);
82+
$connection->expects($this->once())->method('send')->with(base64_encode($encoded['body']), $encoded['headers']);
83+
84+
$serializer = $this->createMock(SerializerInterface::class);
85+
$serializer->method('encode')->with($envelope)->willReturn($encoded);
86+
87+
$sender = new AmazonSqsSender($connection, $serializer);
88+
$sender->send($envelope);
89+
}
7590
}

‎src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/AmazonSqsSender.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/AmazonSqsSender.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function __construct(Connection $connection, SerializerInterface $seriali
3838
public function send(Envelope $envelope): Envelope
3939
{
4040
$encodedMessage = $this->serializer->encode($envelope);
41+
$encodedMessage = $this->complyWithAmazonSqsRequirements($encodedMessage);
4142

4243
/** @var DelayStamp|null $delayStamp */
4344
$delayStamp = $envelope->last(DelayStamp::class);
@@ -75,4 +76,20 @@ public function send(Envelope $envelope): Envelope
7576

7677
return $envelope;
7778
}
79+
80+
/**
81+
* @see https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessage.html
82+
*
83+
* @param array{body: string, headers?: array<string>} $encodedMessage
84+
*
85+
* @return array{body: string, headers?: array<string>}
86+
*/
87+
private function complyWithAmazonSqsRequirements(array $encodedMessage): array
88+
{
89+
if (preg_match('/[^\x20-\x{D7FF}\xA\xD\x9\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]/u', $encodedMessage['body'])) {
90+
$encodedMessage['body'] = base64_encode($encodedMessage['body']);
91+
}
92+
93+
return $encodedMessage;
94+
}
7895
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.