diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-07-01 20:47:04 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-07-02 11:42:51 +0200 |
commit | 62e3de1bdb5df865cf9bbf833273b015b3513989 (patch) | |
tree | 20aa7c8d2a9f93194c3f0c8cdd7e4c77db1cfa62 /lib/public/appframework | |
parent | 5580b0e7c0856c338d5ca975e5654a1207ad4dde (diff) | |
download | nextcloud-server-62e3de1bdb5df865cf9bbf833273b015b3513989.tar.gz nextcloud-server-62e3de1bdb5df865cf9bbf833273b015b3513989.zip |
Check if response could get generated
`json_encode` fails hard on PHP >= 5.5 if a non UTF-8 value is specified by returning false. Older PHP versions just nullify the value which makes it at least somewhat usable.
This leads to very confusing errors which are very hard to debug since developers are usually not aware of this. In this case I'd consider throwing a fatal exception – since it arguably is an error situation – is a fair solution since this makes developers and administrators aware of any occurence of the problem so that these bugs can get fixed.
Fixes https://github.com/owncloud/core/issues/17265
Diffstat (limited to 'lib/public/appframework')
-rw-r--r-- | lib/public/appframework/http/jsonresponse.php | 11 |
1 files changed, 9 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; } /** |