mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-25 17:57:28 +08:00
328bc88f02
Dumping details that were binary, such as the jpegphoto data, would cause the dump to fail on the encoding to JSON. This change forces content to be UTF8 before dumping. Updated existing test to cover. Closes #3396
32 lines
668 B
PHP
32 lines
668 B
PHP
<?php
|
|
|
|
namespace BookStack\Exceptions;
|
|
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class JsonDebugException extends Exception
|
|
{
|
|
protected array $data;
|
|
|
|
/**
|
|
* JsonDebugException constructor.
|
|
*/
|
|
public function __construct(array $data)
|
|
{
|
|
$this->data = $data;
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Convert this exception into a response.
|
|
* We add a manual data conversion to UTF8 to ensure any binary data is presentable as a JSON string.
|
|
*/
|
|
public function render(): JsonResponse
|
|
{
|
|
$cleaned = mb_convert_encoding($this->data, 'UTF-8');
|
|
|
|
return response()->json($cleaned);
|
|
}
|
|
}
|