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 /tests | |
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 'tests')
-rw-r--r-- | tests/lib/appframework/http/JSONResponseTest.php | 11 |
1 files changed, 11 insertions, 0 deletions
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; |