From 9bdf0973b337cbf73287422cc5fdceabc8703e61 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 4 Jul 2017 11:31:38 +0200 Subject: API: Fix return type of empty values in file/history If the array is not casted to a object, json_encode will encode it as [] if empty, but {} if it contains data. Always return an object by casting the array to an object if it is empty. Fixes #15 Signed-off-by: Florian Pritz --- application/test/Test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'application/test/Test.php') diff --git a/application/test/Test.php b/application/test/Test.php index 33278436b..b8052fbba 100644 --- a/application/test/Test.php +++ b/application/test/Test.php @@ -90,10 +90,14 @@ abstract class Test { // Method: POST, PUT, GET etc // Data: array("param" => "value") ==> index.php?param=value // Source: http://stackoverflow.com/a/9802854/953022 - protected function CallAPI($method, $url, $data = false) + protected function CallAPI($method, $url, $data = false, $return_json = false) { $result = $this->SendHTTPRequest($method, $url, $data); + if ($return_json) { + return $result; + } + $json = json_decode($result, true); if ($json === NULL) { $this->t->fail("json decode"); -- cgit v1.2.3-24-g4f1b