mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Use JSON_THROW_ON_ERROR instead of custom error handling
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
7140201a32
commit
3901a93c72
2 changed files with 4 additions and 10 deletions
|
|
@ -64,13 +64,7 @@ class JSONResponse extends Response {
|
|||
* @throws \Exception If data could not get encoded
|
||||
*/
|
||||
public function render() {
|
||||
$response = json_encode($this->data, JSON_HEX_TAG);
|
||||
if ($response === false) {
|
||||
throw new \Exception(sprintf('Could not json_encode due to invalid ' .
|
||||
'non UTF-8 characters in the array: %s', var_export($this->data, true)));
|
||||
}
|
||||
|
||||
return $response;
|
||||
return json_encode($this->data, JSON_HEX_TAG | JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -88,10 +88,10 @@ class JSONResponseTest extends \Test\TestCase {
|
|||
$this->assertEquals($expected, $this->json->render());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testRenderWithNonUtf8Encoding() {
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage('Could not json_encode due to invalid non UTF-8 characters in the array: array (');
|
||||
$this->expectException(\JsonException::class);
|
||||
$this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded');
|
||||
|
||||
$params = ['test' => hex2bin('e9')];
|
||||
$this->json->setData($params);
|
||||
|
|
|
|||
Loading…
Reference in a new issue