Skip to content

Commit 98c2716

Browse files
committed
Restore the mb_convert but with checks
check if string and if not already utf-8
1 parent 20dc6b6 commit 98c2716

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/Barryvdh/Debugbar/LaravelDebugBar.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,59 @@ public function collectConsole(){
537537
$this->data[$name] = $collector->collect();
538538
}
539539

540+
// Remove all invalid (non UTF-8) characters
541+
array_walk_recursive($this->data, function(&$item){
542+
if(is_string($item) && !mb_check_encoding($item, 'UTF-8')){
543+
$item = mb_convert_encoding($item, 'UTF-8', 'UTF-8');
544+
}
545+
});
546+
540547
if ($this->storage !== null) {
541548
$this->storage->save($this->getCurrentRequestId(), $this->data);
542549
}
543550

544551
return $this->data;
545552
}
546553

554+
/**
555+
* Collects the data from the collectors
556+
*
557+
* @return array
558+
*/
559+
public function collect()
560+
{
561+
/** @var Request $request */
562+
$request = $this->app['request'];
563+
564+
$this->data = array(
565+
'__meta' => array(
566+
'id' => $this->getCurrentRequestId(),
567+
'datetime' => date('Y-m-d H:i:s'),
568+
'utime' => microtime(true),
569+
'method' => $request->getMethod(),
570+
'uri' => $request->getRequestUri(),
571+
'ip' => $request->getClientIp()
572+
)
573+
);
574+
575+
foreach ($this->collectors as $name => $collector) {
576+
$this->data[$name] = $collector->collect();
577+
}
578+
579+
// Remove all invalid (non UTF-8) characters
580+
array_walk_recursive($this->data, function(&$item){
581+
if(is_string($item) && !mb_check_encoding($item, 'UTF-8')){
582+
$item = mb_convert_encoding($item, 'UTF-8', 'UTF-8');
583+
}
584+
});
585+
586+
587+
if ($this->storage !== null) {
588+
$this->storage->save($this->getCurrentRequestId(), $this->data);
589+
}
590+
591+
return $this->data;
592+
}
547593

548594
/**
549595
* Magic calls for adding messages

0 commit comments

Comments
 (0)