aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-07-06 12:29:07 +0200
committerVincent Petry <pvince81@owncloud.com>2015-07-06 12:29:07 +0200
commit073e6546922c1b326a1ea733e9505e2350419590 (patch)
tree69c3d3b4b4abfc0d128c5a412e162cde3ca756b6
parent4dbc8ab77fb9aa45f250302a46c4146d63ea0cc2 (diff)
parent62e3de1bdb5df865cf9bbf833273b015b3513989 (diff)
downloadnextcloud-server-073e6546922c1b326a1ea733e9505e2350419590.tar.gz
nextcloud-server-073e6546922c1b326a1ea733e9505e2350419590.zip
Merge pull request #17304 from owncloud/fix-17265
Check if response could get generated
-rw-r--r--lib/public/appframework/http/jsonresponse.php11
-rw-r--r--tests/lib/appframework/http/JSONResponseTest.php11
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/public/appframework/http/jsonresponse.php b/lib/public/appframework/http/jsonresponse.php
index 1a770109d45..456a5616d4d 100644
--- a/lib/public/appframework/http/jsonresponse.php
+++ b/lib/public/appframework/http/jsonresponse.php
@@ -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;
}
/**
diff --git a/tests/lib/appframework/http/JSONResponseTest.php b/tests/lib/appframework/http/JSONResponseTest.php
index cdd8d269b41..692237f57b2 100644
--- a/tests/lib/appframework/http/JSONResponseTest.php
+++ b/tests/lib/appframework/http/JSONResponseTest.php
@@ -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;