From a30466d0f8de3710b53fcacb7d44777bd133d991 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 16 Jun 2014 14:49:51 +0200 Subject: [PATCH] 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.. --- src/DebugBar/DebugBar.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/DebugBar/DebugBar.php b/src/DebugBar/DebugBar.php index 5ca2c4e..fbd0205 100644 --- a/src/DebugBar/DebugBar.php +++ b/src/DebugBar/DebugBar.php @@ -214,6 +214,13 @@ class DebugBar implements ArrayAccess foreach ($this->collectors as $name => $collector) { $this->data[$name] = $collector->collect(); } + + // Remove all invalid (non UTF-8) characters + array_walk_recursive($this->data, function(&$item){ + if (is_string($item) && !mb_check_encoding($item, 'UTF-8')) { + $item = mb_convert_encoding($item, 'UTF-8', 'UTF-8'); + } + }); if ($this->storage !== null) { $this->storage->save($this->getCurrentRequestId(), $this->data);