From 9bdcf522c37246b699aeffed02e3aa68fdfffea8 Mon Sep 17 00:00:00 2001 From: Ryan White Date: Mon, 5 Feb 2018 09:21:23 +0100 Subject: [PATCH] Adding breadcrumbs to sanitize / serialize. (#538) (plus fix CS) (cherry picked from commit 0904031) --- lib/Raven/Client.php | 3 +++ tests/ClientTest.php | 35 +++++++++++++++++++++++++++++++++++ tests/StacktraceTest.php | 3 +-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 23e36beb1..0f7c3e0aa 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -508,6 +508,9 @@ public function sanitize(&$data) if (!empty($data['contexts'])) { $data['contexts'] = $this->serializer->serialize($data['contexts'], 5); } + if (!empty($data['breadcrumbs'])) { + $data['breadcrumbs'] = $this->serializer->serialize($data['breadcrumbs'], 5); + } } public function sendUnsentErrors() diff --git a/tests/ClientTest.php b/tests/ClientTest.php index a09b9bf0b..1db3fd5e7 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -643,6 +643,41 @@ public function testSanitizeContexts() ]], $data); } + public function testSanitizeBreadcrumbs() + { + $client = ClientBuilder::create()->getClient(); + $data = [ + 'breadcrumbs' => [ + [ + 'message' => 'foo', + 'utf8' => pack('NA3CC', 3, 'aBc', 0x0D, 0x0A), + 'data' => [ + 'line' => 1216, + 'bindings' => [ + ['foo', pack('NA3CC', 3, 'aBc', 0x0D, 0x0A)], + ], + ], + ], + ], + ]; + $client->sanitize($data); + + $this->assertEquals([ + 'breadcrumbs' => [ + [ + 'message' => 'foo', + 'utf8' => mb_convert_encoding(pack('NA3CC', 3, 'aBc', 0x0D, 0x0A), 'UTF-8'), + 'data' => [ + 'line' => 1216, + 'bindings' => [ + ['foo', mb_convert_encoding(pack('NA3CC', 3, 'aBc', 0x0D, 0x0A), 'UTF-8')], + ], + ], + ], + ], + ], $data); + } + /** * @covers \Raven\Client::getShutdownFunctionHasBeenSet */ diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index 5b41c9d5e..4b511ae45 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -238,14 +238,13 @@ public function testFromBacktraceWithAnonymousFrame() $this->assertFrameEquals($frames[2], 'TestClass::triggerError', 'path/to/file', 12); } - public function testInAppWithEmptyFrame() { $stack = [ [ 'function' => '{closure}', ], - null + null, ]; $stacktrace = new Stacktrace($this->client);