Skip to content
Snippets Groups Projects
Commit 073e6546 authored by Vincent Petry's avatar Vincent Petry
Browse files

Merge pull request #17304 from owncloud/fix-17265

Check if response could get generated
parents 4dbc8ab7 62e3de1b
Branches
No related tags found
No related merge requests found
......@@ -61,9 +61,16 @@ class JSONResponse extends Response {
* Returns the rendered json
* @return string the rendered json
* @since 6.0.0
* @throws \Exception If data could not get encoded
*/
public function render(){
return json_encode($this->data);
public function render() {
$response = json_encode($this->data);
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;
}
/**
......
......@@ -76,6 +76,17 @@ class JSONResponseTest extends \Test\TestCase {
$this->assertEquals($expected, $this->json->render());
}
/**
* @expectedException \Exception
* @expectedExceptionMessage Could not json_encode due to invalid non UTF-8 characters in the array: array (
* @requires PHP 5.5
*/
public function testRenderWithNonUtf8Encoding() {
$params = ['test' => hex2bin('e9')];
$this->json->setData($params);
$this->json->render();
}
public function testConstructorAllowsToSetData() {
$data = array('hi');
$code = 300;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment