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/controllers/api/v2/file.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'application/controllers') diff --git a/application/controllers/api/v2/file.php b/application/controllers/api/v2/file.php index 6f95d5525..5dedcd508 100644 --- a/application/controllers/api/v2/file.php +++ b/application/controllers/api/v2/file.php @@ -65,6 +65,13 @@ class file extends \controllers\api\api_controller { unset($history['multipaste_items'][$key]['items'][$inner_key]['sort_order']); } } + + foreach (array("items", "multipaste_items") as $key) { + if (empty($history[$key])) { + $history[$key] = (object) array(); + } + } + return $history; } -- cgit v1.2.3-24-g4f1b