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 a16a574

Browse filesBrowse files
tooonifabpot
authored andcommitted
[Messenger] Added check if json_encode succeeded
1 parent 9e7a410 commit a16a574
Copy full SHA for a16a574

File tree

2 files changed

+22
-0
lines changed
Filter options

2 files changed

+22
-0
lines changed

‎src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ public function testGetNonBlocking()
186186
$redis->del('messenger-getnonblocking');
187187
}
188188

189+
public function testJsonError()
190+
{
191+
$redis = new \Redis();
192+
193+
$connection = Connection::fromDsn('redis://localhost/json-error', [], $redis);
194+
195+
try {
196+
$connection->add("\xB1\x31", []);
197+
} catch (TransportException $e) {
198+
}
199+
200+
$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
201+
}
202+
189203
public function testMaxEntries()
190204
{
191205
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();

‎src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ public function add(string $body, array $headers, int $delayInMs = 0): void
248248
'uniqid' => uniqid('', true),
249249
]);
250250

251+
if (false === $message) {
252+
throw new TransportException(json_last_error_msg());
253+
}
254+
251255
$score = (int) ($this->getCurrentTimeInMilliseconds() + $delayInMs);
252256
$added = $this->connection->zadd($this->queue, ['NX'], $score, $message);
253257
} else {
@@ -256,6 +260,10 @@ public function add(string $body, array $headers, int $delayInMs = 0): void
256260
'headers' => $headers,
257261
]);
258262

263+
if (false === $message) {
264+
throw new TransportException(json_last_error_msg());
265+
}
266+
259267
if ($this->maxEntries) {
260268
$added = $this->connection->xadd($this->stream, '*', ['message' => $message], $this->maxEntries, true);
261269
} else {

0 commit comments

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