Skip to content

Commit a30466d

Browse files
committed
Force convert to UTF-8
Not sure if this is the best/most efficient method and haven't really check the impact, but what do you think about this? I keep running into edge cases when dealing with debugging non-utf8 data, this would make sure that all strings are utf8, or converted to utf-8 (with non-utf8 characters replaced) Otherwise json_encode will throw an exception..
1 parent e2029f1 commit a30466d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/DebugBar/DebugBar.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ public function collect()
214214
foreach ($this->collectors as $name => $collector) {
215215
$this->data[$name] = $collector->collect();
216216
}
217+
218+
// Remove all invalid (non UTF-8) characters
219+
array_walk_recursive($this->data, function(&$item){
220+
if (is_string($item) && !mb_check_encoding($item, 'UTF-8')) {
221+
$item = mb_convert_encoding($item, 'UTF-8', 'UTF-8');
222+
}
223+
});
217224

218225
if ($this->storage !== null) {
219226
$this->storage->save($this->getCurrentRequestId(), $this->data);

0 commit comments

Comments
 (0)