8000 merged branch krmcbride/mongo-profiler (PR #5556) · markross/symfony@bd845b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit bd845b3

Browse files
committed
merged branch krmcbride/mongo-profiler (PR symfony#5556)
This PR was merged into the 2.1 branch. Commits ------- c120c4d Added Base64 encoding, decoding to MongoDBProfilerStorage Discussion ---------- [HttpKernel] Added UTF8 encoding, decoding to MongoDBProfilerStorage Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes It didn't take long for us to hit a non-utf8 error using the new `MongoDBProfilerStorage`. I'm pretty sure the culprit was the Switfmailer DataCollector serializing a message with a PDF attachment. I thought this would be a good failsafe, although one could ask whether mail message attachments should be serialized at all... --------------------------------------------------------------------------- by krmcbride at 2012-09-28T17:28:02Z Switched encoding/decoding to base64
2 parents 6f30614 + c120c4d commit bd845b3

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/Symfony/Component/HttpKernel/Profiler/MongoDbProfilerStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function write(Profile $profile)
9595
$record = array(
9696
'_id' => $profile->getToken(),
9797
'parent' => $profile->getParentToken(),
98-
'data' => serialize($profile->getCollectors()),
98+
'data' => base64_encode(serialize($profile->getCollectors())),
9999
'ip' => $profile->getIp(),
100100
'method' => $profile->getMethod(),
101101
'url' => $profile->getUrl(),
@@ -220,7 +220,7 @@ private function getProfile(array $data)
220220
$profile->setMethod($data['method']);
221221
$profile->setUrl($data['url']);
222222
$profile->setTime($data['time']);
223-
$profile->setCollectors(unserialize($data['data']));
223+
$profile->setCollectors(unserialize(base64_decode($data['data'])));
224224

225225
return $profile;
226226
}

src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use Symfony\Component\HttpKernel\Profiler\MongoDbProfilerStorage;
1515
use Symfony\Component\HttpKernel\Profiler\Profile;
16+
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
17+
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpFoundation\Response;
1619

1720
class DummyMongoDbProfilerStorage extends MongoDbProfilerStorage
1821
{
@@ -22,6 +25,28 @@ public function getMongo()
2225
}
2326
}
2427

28+
class MongoDbProfilerStorageTestDataCollector extends DataCollector
29+
{
30+
public function setData($data)
31+
{
32+
$this->data = $data;
33+
}
34+
35+
public function getData()
36+
{
37+
return $this->data;
38+
}
39+
40+
public function collect(Request $request, Response $response, \Exception $exception = null)
41+
{
42+
}
43+
44+
public function getName()
45+
{
46+
return 'test_data_collector';
47+
}
48+
}
49+
2550
class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest
2651
{
2752
protected static $storage;
@@ -62,6 +87,28 @@ public function testCleanup()
6287
self::$storage->purge();
6388
}
6489

90+
public function testUtf8()
91+
{
92+
$profile = new Profile('utf8_test_profile');
93+
94+
$data = 'HЁʃʃϿ, ϢorЃd!';
95+
$nonUtf8Data = mb_convert_encoding($data, 'UCS-2');
96+
97+
$collector = new MongoDbProfilerStorageTestDataCollector();
98+
$collector->setData($nonUtf8Data);
99+
100+
$profile->setCollectors(array($collector));
101+
102+
self::$storage->write($profile);
103+
104+
$readProfile = self::$storage->read('utf8_test_profile');
105+
$collectors = $readProfile->getCollectors();
106+
107+
$this->assertCount(1, $collectors);
108+
$this->assertArrayHasKey('test_data_collector', $collectors);
109+
$this->assertEquals($nonUtf8Data, $collectors['test_data_collector']->getData(), 'Non-UTF8 data is properly encoded/decoded');
110+
}
111+
65112
/**
66113
* @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
67114
*/
@@ -79,3 +126,4 @@ protected function setUp()
79126
}
80127
}
81128
}
129+

0 commit comments

Comments
 (0)
0