diff --git a/pkg/enqueue-bundle/Profiler/MessageQueueCollector.php b/pkg/enqueue-bundle/Profiler/MessageQueueCollector.php index de5fa59bc..b3e2b5f0f 100644 --- a/pkg/enqueue-bundle/Profiler/MessageQueueCollector.php +++ b/pkg/enqueue-bundle/Profiler/MessageQueueCollector.php @@ -5,6 +5,7 @@ use Enqueue\Client\MessagePriority; use Enqueue\Client\ProducerInterface; use Enqueue\Client\TraceableProducer; +use Enqueue\Util\JSON; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\DataCollector; @@ -65,19 +66,13 @@ public function prettyPrintPriority($priority) } /** - * @param string $message + * @param mixed $body * * @return string */ - public function prettyPrintMessage($message) + public function ensureString($body) { - if (is_scalar($message)) { - return htmlspecialchars($message); - } - - return htmlspecialchars( - json_encode($message, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) - ); + return is_string($body) ? $body : JSON::encode($body); } /** diff --git a/pkg/enqueue-bundle/Resources/views/Profiler/panel.html.twig b/pkg/enqueue-bundle/Resources/views/Profiler/panel.html.twig index a8f783dfc..635a540d7 100644 --- a/pkg/enqueue-bundle/Resources/views/Profiler/panel.html.twig +++ b/pkg/enqueue-bundle/Resources/views/Profiler/panel.html.twig @@ -44,7 +44,10 @@ {{ sentMessage.topic }} - {{ sentMessage.body[0:40] }}... Show trace + + {{ collector.ensureString(sentMessage.body)[0:40] }}{% if collector.ensureString(sentMessage.body)[0:40] != collector.ensureString(sentMessage.body) %}...{% endif %} + + Show trace
{{ profiler_dump(sentMessage.body) }} diff --git a/pkg/enqueue-bundle/Tests/Unit/Profiler/MessageQueueCollectorTest.php b/pkg/enqueue-bundle/Tests/Unit/Profiler/MessageQueueCollectorTest.php index b6ec4f842..62f7d6c1c 100644 --- a/pkg/enqueue-bundle/Tests/Unit/Profiler/MessageQueueCollectorTest.php +++ b/pkg/enqueue-bundle/Tests/Unit/Profiler/MessageQueueCollectorTest.php @@ -71,21 +71,19 @@ public function testShouldPrettyPrintUnknownPriority() $this->assertEquals('unknownPriority', $collector->prettyPrintPriority('unknownPriority')); } - public function testShouldPrettyPrintScalarMessage() + public function testShouldEnsureStringKeepStringSame() { $collector = new MessageQueueCollector($this->createProducerMock()); - $this->assertEquals('foo', $collector->prettyPrintMessage('foo')); - $this->assertEquals('<p>', $collector->prettyPrintMessage('

')); + $this->assertEquals('foo', $collector->ensureString('foo')); + $this->assertEquals('bar baz', $collector->ensureString('bar baz')); } - public function testShouldPrettyPrintArrayMessage() + public function testShouldEnsureStringEncodeArrayToJson() { $collector = new MessageQueueCollector($this->createProducerMock()); - $expected = "[\n "foo",\n "bar"\n]"; - - $this->assertEquals($expected, $collector->prettyPrintMessage(['foo', 'bar'])); + $this->assertEquals('["foo","bar"]', $collector->ensureString(['foo', 'bar'])); } /**